#include using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define INF ((1LL<<62)-(1LL<<31)) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() typedef long long ll; typedef pair pl; int main() { int n,m,q; cin >> n >> m >> q; vector> flag(n,vector (m,false)); rep(i,q) { int a,b; cin >> a >> b; a--; b--; flag[a][b]=true; } vector> dp(n+1,vector (m+1,0)); rep(i,n) rep(j,m) { if(flag[i][j]) dp[i+1][j+1]=dp[i][j]+1; else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]); } cout << dp[n][m] << endl; return 0; }