// #include // using namespace atcoder; #include using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vll = vector; using vvi = vector>; using vvll = vector>; const int inf = 1e9; const ll lim = 1e18; int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; int tree[1005]; void update(int i, int a) { i++; while (i < 1004) { tree[i] = max(tree[i], a); i += i & -i; } } int getmax(int i) { i++; int res = -inf; while (i > 0) { res = max(res, tree[i]); i -= i & -i; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); rep(i, 1005) tree[i] = -inf; update(0,0); int n, m, q; cin >> n >> m >> q; vector> ab; rep(i, q) { int a, b; cin >> a >> b; ab.emplace_back(a, -b); } sort(ab.begin(), ab.end()); for (auto [a, b] : ab) { b = -b; int pre = getmax(b - 1); update(b, pre + 1); } int ans = getmax(1004); cout << ans << endl; return 0; }