import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = Integer.parseInt(sa[1]); int q = Integer.parseInt(sa[2]); Obj[] arr = new Obj[q]; for (int i = 0; i < q; i++) { sa = br.readLine().split(" "); Obj o = new Obj(); o.a = Integer.parseInt(sa[0]); o.b = Integer.parseInt(sa[1]); arr[i] = o; } br.close(); Arrays.sort(arr, (o1, o2) -> { if (o1.a != o2.a) { return o1.a - o2.a; } return o2.b - o1.b; }); int[] dp = new int[m + 1]; for (int i = 1; i <= m; i++) { dp[i] = Integer.MAX_VALUE; } for (int i = 0; i < q; i++) { int idx = Arrays.binarySearch(dp, arr[i].b); if (idx < 0) idx = ~idx; dp[idx] = arr[i].b; } int lis = Arrays.binarySearch(dp, Integer.MAX_VALUE - 1); if (lis < 0) { lis = ~lis; lis--; } System.out.println(lis); } static class Obj { int a, b; } }