2 5 10
2 2
1 1
1 4
2 1
1 2
1 5
2 4
2 5
1 3
2 3
 2 2 2
1 1
2 2
 3 3 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
 7 5 35
5 3
3 5
1 1
2 5
6 4
7 2
5 1
3 4
6 5
7 3
4 1
2 2
4 2
2 4
4 3
3 3
6 1
1 2
4 5
1 3
2 1
5 5
7 5
7 1
6 2
1 4
1 5
3 2
4 4
5 2
2 3
6 3
7 4
5 4
3 1
 1 5 4
1 1
1 2
1 4
1 5
 1 1 1
1 1
 5 7 21
4 4
4 5
5 5
5 6
5 7
5 1
5 2
4 2
3 2
3 1
3 7
3 6
2 6
1 6
1 7
1 1
1 2
1 3
1 4
2 4
3 4
 2 1 1
1 1
 2 2 4
2 1
1 1
1 2
2 2
 3000 3000 1
2222 738
 5 7 35
1 2
2 3
5 1
5 7
4 4
5 3
3 1
2 6
4 5
2 7
4 1
2 1
2 2
1 7
5 6
3 6
4 6
1 6
1 1
3 3
3 4
4 2
2 5
5 5
3 5
2 4
1 5
1 3
4 3
5 4
1 4
3 7
4 7
3 2
5 2
 5 4 1
4 1
 3 4 12
2 3
3 2
2 2
2 1
1 2
3 1
1 4
1 3
3 3
2 4
3 4
1 1
 3 3 3
1 1
2 2
3 3

8
 1
 6
 26
 4
 0
 20
 0
 2
 1
 28
 1
 9
 3

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,abm,mmx,tune=native")
using namespace std;
const int64_t INF = (int64_t)(2e18);
const long long inf = (long long)(1e9 + 7);
const long long maxn = 500 * 1000 + 100;
chrono::time_point<chrono::steady_clock> cl;
double current_time() {
  return (double)(chrono::steady_clock::now() - cl).count() / 1e9;
}
struct dsu {
  vector<long long> p, s, B;
  dsu() {}
  dsu(long long n) {
    p.resize(n);
    s.assign(n, 1);
    iota((p).begin(), (p).end(), 0);
  }
  long long root(long long v) { return p[v] == v ? v : root(p[v]); }
  void unite(long long a, long long b) {
    a = root(a);
    b = root(b);
    if (a == b) {
      B.push_back(-1);
      return;
    }
    if (s[a] < s[b]) swap(a, b);
    s[a] += s[b];
    p[b] = a;
    B.push_back(b);
  }
  void rollback() {
    long long b = B.back();
    B.pop_back();
    if (b == -1) return;
    s[p[b]] -= s[b];
    p[b] = b;
  }
};
long long active[3002][3002];
int32_t main() {
  cl = chrono::steady_clock::now();
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  long long rows, cols, n;
  cin >> rows >> cols >> n;
  long long res = n;
  auto coor = [&](long long r, long long c) { return r * (2 * cols) + c; };
  dsu u(2 * rows * cols);
  for (long long i = 0; i < n; ++i) {
    long long r, c;
    cin >> r >> c;
    --r;
    --c;
    active[r][c] = 1;
    long long torollback = 0;
    for (long long dr = -1; dr <= 1; ++dr) {
      for (long long dc = -1; dc <= 1; ++dc) {
        if (r + dr < 0) continue;
        if (r + dr >= rows) continue;
        if (c + dc < 0) continue;
        if (active[r + dr][(c + dc + cols) % cols] == 0) continue;
        torollback++;
        u.unite(coor(r, c), coor(r + dr, c + dc));
      }
      for (long long dc = -1; dc <= 1; ++dc) {
        if (r + dr < 0) continue;
        if (r + dr >= rows) continue;
        if (c + dc >= cols) continue;
        if (active[r + dr][(c + dc + cols) % cols] == 0) continue;
        torollback++;
        u.unite(coor(r, c + cols), coor(r + dr, c + dc + cols));
      }
    }
    if (u.root(coor(r, c)) == u.root(coor(r, c + cols))) {
      --res;
      active[r][c] = 0;
      for (long long k = 0; k < torollback; ++k) u.rollback();
    }
  }
  cout << res;
  return 0;
}
