#include <bits/stdc++.h> using namespace std; struct node { int x , y ; void rd ( ) { cin >> x >> y ; } } s [100005] ; int stack [100001] = { 1e-9 } ; bool cmp ( node a , node b ) { return ( a . x == b . x ? a . y < b . y : a . x < b . x ) ; } int main() { int n , m , p , longest = 0 ; cin >> n >> m >> p ; for ( int i = 1 ; i <= p ; i ++ ) { s [i] . rd ( ) ; } sort ( s , s + p , cmp ) ; for ( int i = 1 ; i <= p ; i ++ ) { if ( s [i] . y > stack [longest] ) { Stack [++ longest] = s [i] . y ; } else { int j = upper_bound ( stack , stack + longest , s [i] . y ) - stack ; stack [j] = s [i] . y ; } } cout << longest << endl ; return 0; }