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>
using namespace std;
const int MAXD = 3007, MAXN = 100007;
int A[MAXD][MAXD], par[MAXN], dsu[MAXN], R, C, N;
int get(int x) {
  return (dsu[x] < 0 ? (x << 1) : dsu[x] = get(dsu[x] >> 1) ^ par[x]);
}
void join(int x, int y, int w) {
  x = get(x), y = get(y);
  w ^= (x & 1) ^ (y & 1);
  x >>= 1, y >>= 1;
  if (x == y) {
    assert(w == 0);
    return;
  }
  if (dsu[x] > dsu[y]) swap(x, y);
  par[y] = w, dsu[x] += dsu[y], dsu[y] = (x << 1) ^ w;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> R >> C >> N;
  int ans = 0;
  for (int id = 1; id <= N; ++id) {
    int r, c;
    cin >> r >> c;
    A[r][c] = id, dsu[id] = -1;
    vector<int> vec;
    for (int dx = -1; dx <= 1; ++dx)
      for (int dy = -1; dy <= 1; ++dy) {
        if ((dx == 0 && dy == 0) || r + dx < 1 || r + dx > R) continue;
        int r0 = r + dx, c0 = c + dy, w = 0;
        if (c0 == 0)
          c0 = C, w = 1;
        else if (c0 == C + 1)
          c0 = 1, w = 1;
        if (!A[r0][c0]) continue;
        vec.push_back(get(A[r0][c0]) ^ w);
      }
    sort(vec.begin(), vec.end());
    bool bad = false;
    for (int i = 0; i < (int)vec.size() - 1; ++i)
      if ((vec[i] ^ vec[i + 1]) == 1) {
        bad = true;
        break;
      }
    if (bad) continue;
    ++ans;
    for (int x : vec) join(id, x >> 1, x & 1);
  }
  cout << ans << endl;
}
