#include using namespace std; using ll = long long; const ll MOD = 1000000007; using P = pair; #define rep(i, n) for(int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() int main(){ int n,m,q; cin >> n >> m >> q; vector cx(q,MOD),cy(q,MOD); rep(i,q){ int a,b; cin >> a >> b; int low = lower_bound(all(cx),a) - cx.begin(); int up = upper_bound(all(cx),a) - cx.begin(); if(low == up){ if(low && cy[low-1] >= b) continue; cx[low] = a; cy[low] = b; }else{ int itr = lower_bound(cy.begin()+low, cy.begin()+up, b) - cy.begin(); if(itr && cy[itr-1] >= b) continue; cx[itr] = a; cy[itr] = b; } } int ans = 0; rep(i,q){ if(cx[i]==MOD) break; ans++; } cout << ans << endl; return 0; }