#include<bits/stdc++.h>
using namespace std;

#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
const long long INF=1e18;
typedef pair<ll,ll> pll;
#define F first
#define S second



int main(){
  ll r,s,p;
  cin>>r>>s>>p;
  vector<ll> A(p);
  for(int i=0;i<p;i++){
    ll x,y;
    cin>>x>>y;
    if(y<=s){y--;}
    x--;
    A[i]=abs(s-y)+r-x;
  }
  sort(A.begin(),A.end());
  for(int i=1;i<p;i++){
    A[i]=max(A[i],A[i-1]+1);
  }
  cout<<A.back()<<endl;

  
  
  return 0;
}

