import java.io.*;
import java.util.*;
import java.math.*;

public class maxpiece_ab implements Runnable {

	final int MAX = (int) 1e9;
	final int MAXK = (int) 1e5;

	private void solve() throws IOException {
		int n = in.nextInt();
		assert 1 <= n && n <= MAX;
		int m = in.nextInt();
		assert 1 <= m && m <= MAX;

		int k = in.nextInt();
		assert 0 <= k && k <= MAXK;

		int[][] c = new int[2][k + 2];
		c[0][k + 1] = n;
		c[1][k + 1] = m;

		for (int i = 0; i < k; ++i) {
			int t = in.nextInt();
			assert 0 <= t && t <= 1;
			int v = in.nextInt();
			assert 0 < v && v < (t == 0 ? n : m);
			c[t][i] = v;
		}

		int[] max = new int[2];
		for (int i = 0; i < c.length; ++i) {
			Arrays.sort(c[i]);
			for (int j = 1; j < c[i].length; ++j) {
				max[i] = Math.max(max[i], c[i][j] - c[i][j - 1]);
			}
		}
		out.println(Math.min(max[0], max[1]));
	}

	final int INF = (int) 1e9;

	SimpleScanner in;
	PrintWriter out;

	@Override
	public void run() {
		try {
			in = new SimpleScanner(new FileReader("maxpiece.in"));
			out = new PrintWriter("maxpiece.out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	public static void main(String[] args) {
		new Thread(new maxpiece_ab()).start();
	}

	class SimpleScanner extends BufferedReader {

		private StringTokenizer st;
		private boolean eof;

		public SimpleScanner(Reader a) {
			super(a);
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(readLine());
				} catch (Exception e) {
					eof = true;
					return "";
				}
			}
			return st.nextToken();
		}

		boolean seekEof() {
			String s = next();
			if ("".equals(s) && eof)
				return true;
			st = new StringTokenizer(s + " " + st.toString());
			return false;
		}

		private String cnv(String s) {
			if (s.length() == 0)
				return "0";
			return s;
		}

		int nextInt() {
			return Integer.parseInt(cnv(next()));
		}

		double nextDouble() {
			return Double.parseDouble(cnv(next()));
		}

		long nextLong() {
			return Long.parseLong(cnv(next()));
		}
	}
}