import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int q = sc.nextInt(); Person[] persons = new Person[q + 1]; persons[0] = new Person(0, 0); ArrayList> dp = new ArrayList<>(); dp.add(new ArrayList<>()); dp.get(0).add(0); for (int i = 1; i <= q; i++) { persons[i] = new Person(sc.nextInt(), sc.nextInt()); for (int j = dp.size() - 1; j >= 0; j--) { boolean ok = false; for (int x : dp.get(j)) { if (persons[x].enable(persons[i])) { if (j == dp.size() - 1) { dp.add(new ArrayList<>()); } dp.get(j + 1).add(i); ok = true; break; } } if (ok) { break; } } } System.out.println(dp.size() - 1); } static class Person { int left; int right; public Person(int left, int right) { this.left = left; this.right = right; } public boolean enable(Person another) { return left < another.left && right < another.right; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }