#include using ll = long long; using std::cin; using std::cout; using std::endl; std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); template inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int inf = (int)1e9 + 7; const long long INF = 1LL << 60; void solve([[maybe_unused]] int CASE) { int n, m, q; cin >> n >> m >> q; std::vector> vp(q); for (int i = 0; i < q; ++i) { cin >> vp[i].first >> vp[i].second; } std::vector dp(2, std::vector(q + 1, -1)); int cur = 0, nxt = 1; dp[0][0] = 0; for (int i = 0; i < q; ++i) { std::fill(dp[nxt].begin(), dp[nxt].end(), -1); for (int j = 0; j <= i; ++j) { if (dp[cur][j] == -1) continue; if (vp[j].first < vp[i].first and vp[j].second < vp[i].second) { chmax(dp[nxt][i], dp[cur][j] + 1); } chmax(dp[nxt][j], dp[cur][j]); } chmax(dp[nxt][i], 1); std::swap(cur, nxt); } cout << *std::max_element(dp[cur].begin(), dp[cur].end()) << endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int kkt = 1; // cin >> kkt; for (int jupi = 1; jupi <= kkt; jupi++) solve(jupi); return 0; }