#include #define rep(i, l, r) for (int i = (l); i < (r); i++) using namespace std; typedef long long ll; int main() { int N, M, Q, a, b; cin >> N >> M >> Q; vector> ok(N, vector(M, false)); rep(i, 0, Q) { cin >> a >> b; ok[a - 1][b - 1] = true; } vector> dp(N + 1, vector (M + 1, 0)); rep(i, 0, N) { rep(j, 0, M) { dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]); if (ok[i][j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1); } } cout << dp[N][M] << endl; /* rep(i, 0, N + 1) { rep(j, 0, M + 1) { cout << dp[i][j] << " "; } cout << endl; } */ }