#include #include int f[1005][1005]; int edge[1005][1005]; int main(){ int n,m,q; scanf("%d%d%d",&n,&m,&q); for(int i = 0; i < q; i++){ int u,v; scanf("%d%d",&u,&v); edge[u][v] = 1; } f[0][0] = 0; for(int i = 1; i <= n; i++){ for(int j = 0; j <= m; j++){ f[i][j] = 0; if(j){ f[i][j] = std::max(f[i][j], f[i][j-1]); if(edge[i][j]){ f[i][j] = std::max(f[i][j], f[i-1][j-1]+1); } } } } printf("%d\n",f[n][m]); return 0; }