#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

ll dp[1010][1010];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n,m,q;
  cin>>n>>m>>q;
  vector<int> A(q),B(q);
  rep(i,q){
    cin>>A[i]>>B[i];
  }
  map<pair<int,int>,int> M;
  rep(i,q) M[{A[i],B[i]}]=1;
  
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(M[{i,j}]==0) dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
      else dp[i][j]=dp[i-1][j-1]+1;
    }
  }
  cout<<dp[n][m]<<endl;
  
  return 0;
}