#include <fstream>
#include <vector>
using namespace std;
ifstream cin ("orase.in");
ofstream cout ("orase.in");
vector<vector<int>> drum(1000001);
int main()
{
int M, N, a, b, max_overall = 0, max_till_now = 0;
cin >> M >> N;
for(int i = 0; i < N; i++)
{
cin >> a >> b;
drum[a].push_back(b);
}
int ahem = 0;
for(auto t : drum)
{
if(!t.empty()) break;
ahem++;
}
for(auto t : drum[ahem]) if(t > max_till_now && max_till_now != 0) { max_overall = max_till_now + t; max_till_now = t;}
else if(t > max_till_now) max_till_now = t;
for(int i = ahem+1; i <= M; i++)
{
max_till_now++;
for(auto t : drum[i])
{
if(max_overall < max_till_now + t) max_overall = max_till_now + t;
if(t > max_till_now) max_till_now = t;
}
}
cout << max_overall;
}