#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
const int NMAX = 5e5;
pair<int, int> point[1 + NMAX];
ifstream fin ( "orase.in" );
ofstream fout ( "orase.out" );
int main()
{
int m, n; fin >> m >> n;
for ( int i = 1; i <= n; i ++ )
fin >> point[i].first >> point[i].second;
sort ( point + 1, point + n + 1 );
int max_cost = 0; int max_delete = 0;
int answer = 0;
for ( int i = 1; i <= n; i ++ ) {
max_cost = max ( max_cost, point[i].first + point[i].second );
answer = max ( answer, max_cost + max_delete );
max_delete = max ( max_delete, point[i].second - point[i].first );
}
fout << answer;
return 0;
}