#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int r, s, n;
	cin >> r >> s >> n;
	vector<int> a;
	for(int i = 0; i < n; ++i){
		int y, x;
		cin >> y >> x;
		--y; --x;
		int d = r - y;
		if(x < s){
			d += s - 1 - x;
		}else{
			d += x - s;
		}
		a.emplace_back(d);
	}
	sort(a.begin(), a.end());
	int answer = 0;
	for(int i = 0; i < n; ++i){
		answer = max(a[i], answer + 1);
	}
	cout << answer + 1 << endl;
	return 0;
}


