#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n, m, q; cin >> n >> m >> q; vector> is_ok(n + 1, vector(m + 1)); for (int i = 0; i < q; i++) { int a, b; cin >> a >> b; is_ok[a][b] = true; } vector> dp(n + 1, vector(m + 1)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { dp[i][j] = max( {dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1] + is_ok[i][j]}); } } cout << dp[n][m] << endl; }