#include using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() const int mod = 1000000007; const long long INF = 1LL << 60; using ll = long long; int main() { ll N,M,Q; cin >> N >> M >> Q; vector a(Q+1,0),b(Q+1,0); rep(i,Q){ cin >> a[i+1] >> b[i+1]; } //何番目まで考えるか,最後に選んだペア vector dp(Q+10,0); int ans=0; rep(i,Q+1)if(i){ vector dp_=dp; rep(j,i+1){ dp[j]=dp_[j]; rep(k,j+1)if(k<=i-1){ if(a[j]>a[k]&&b[j]>b[k]) dp[j]=max(dp[j],dp_[k]+1); } ans=max(ans,dp[j]); } } cout << ans << endl; }