#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
namespace cent {

	struct Edge {
		int src;
		int dst;
		//long long int cost;
	};
	using Graph = vector<vector<Edge>>;

	class Centroid {
	private:
		int dfs(const Graph&g, const int now, const int from, vector<int>&ch_nums) {
			int sum = 1;
			for (auto &&e : g[now]) {
				if (e.dst == from || oks[e.dst] != -1)continue;
				else {
					sum += dfs(g, e.dst, e.src, ch_nums);
				}
			}
			return ch_nums[now] = sum;
		};

		int find_centroid(const int asize, const vector<vector<Edge>>&graph, const int pre_root, const int pre_from, const vector<int>&ch_nums) {
			for (auto&& e : graph[pre_root]) {
				if (e.dst == pre_from)continue;
				if (oks[e.dst] != -1)continue;
				if (ch_nums[e.dst]>asize / 2)return find_centroid(asize, graph, e.dst, e.src, ch_nums);
			}
			return pre_root;
		}
		void dfs2(const Graph&g, const int now, const int from, vector<long long int>&v, int k) {
			if (v.size() == k) {
				v.push_back(1);
			}
			else {
				v[k]++;
			}

			for (auto&& e : g[now]) {
				if (e.dst == from)continue;
				else if (oks[e.dst] != -1)continue;
				else {
					dfs2(g, e.dst, now, v, k + 1);
				}
			}
		}

		void cent(const vector<vector<Edge>>&graph, const int root, const int from,
			int& fst_centroid, int depth, vector<int>&ch_nums) {
			dfs(graph, root, from, ch_nums);

			int cent_id = find_centroid(ch_nums[root], graph, root, from, ch_nums);


			oks[cent_id] = depth;
			vector<long long int>pv;
			for (auto&& e : graph[cent_id]) {
				if (e.dst == from)continue;
				if (oks[e.dst] != -1)continue;
				vector<long long int>nv(2);
				dfs2(graph, e.dst, cent_id, nv, 1);

				//aminus(nv);
				if (pv.size() < nv.size()) {
					pv.resize(nv.size());
				}
				for (int i = 0; i < nv.size(); ++i) {
					pv[i] += nv[i];
				}
			}
			//aplus(pv);
			for (int i = 0; i<pv.size(); ++i) {
				//distances[i] += pv[i] * 2;
			}

			if (from != -1) {
				centroid_graph[from].push_back(cent_id);
			}
			else {
				fst_centroid = cent_id;
			}
			for (auto e : graph[cent_id]) {
				if (e.dst == from)continue;
				if (oks[e.dst] != -1)continue;
				cent(graph, e.dst, e.src, fst_centroid, depth + 1, ch_nums);
			}
		}

	public:
		vector<vector<long long int>>lens;
		vector<vector<int>> centroid_graph;
		vector<int>parents;
		vector<int>oks;
		map<pair<int, int>, long long int>mp;

		//fst:root  snd:centroid_graph
		void init(const Graph&g) {
			lens.resize(g.size());
			oks = vector<int>(g.size(), -1);
			int root = -1;
			centroid_graph.resize(g.size());
			parents = vector<int>(g.size(), -1);
			vector<int>ch_nums(g.size());
			cent(g, 0, -1, root, 0, ch_nums);

			for (int i = 0; i < centroid_graph.size(); ++i) {
				for (auto&& e : centroid_graph[i]) {
					parents[e] = i;
				}
			}
			return;
		}
	}centroid;


	void addEdge(Graph& g, int a, int b, long long int c) {
		g[a - 1].push_back(Edge{ a - 1,b - 1 });
		g[b - 1].push_back(Edge{ b - 1,a - 1 });
	}
}

void solve() {
	int N,M;cin>>N>>M;
	vector<int>v(N);
	vector<vector<int>>edges(N);
	for (int i = 0; i < N-1; ++i) {
		int a;cin>>a;
		a--;
		edges[i].push_back(a);
		edges[a].push_back(i);
	}
	for (int i = 0; i < M; ++i) {
		int a,b;cin>>a>>b;

	}

}
int main() {
	int R,S,P;cin>>S>>R>>P;
	vector<int>v;
	for (int i = 0; i < P; ++i) {
		int a,b;cin>>a>>b;
		int dx=b<=R?(R-b+1):(b-R);
		v.push_back(dx+S-a+1);
	}
	sort(v.begin(),v.end());
	int now=0;
	for (auto k : v) {
		now=max(now+1,k);
	}
	cout<<now<<endl;

	return 0;
}


Measured memory_bytes: 4912