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>
const int N = 300010, M = 3002;
const int v1[8] = {1, 1, 1, -1, -1, -1, 0, 0};
const int v2[8] = {-1, 0, 1, -1, 0, 1, -1, 1};
int f[M * M], r, c, n, cnt, t1[8], t2[8], Qc;
bool vis[M][M];
struct lr {
  int x, y;
  bool adj() {
    return vis[x + 1][y] | vis[x][y + 1] | vis[x - 1][y] | vis[x][y - 1];
  }
} t[N];
int exc(int x, int y) { return (y - 1) * r + x; }
int get(int u) { return f[u] == u ? u : f[u] = get(f[u]); }
bool check() {
  for (int i = 0; i < 8; ++i)
    for (int j = 0; j < 8; ++j)
      if (t1[i] > 0 && t2[j] > 0 && t1[i] == t2[j]) {
        --cnt;
        return 0;
      }
  return 1;
}
int main() {
  scanf("%d%d%d", &r, &c, &Qc);
  n = r * c * 2 + 5;
  for (int i = 1; i <= n; ++i) f[i] = i;
  while (Qc--) {
    int x, y, a, b, fu, fv, tb;
    scanf("%d%d", &x, &y);
    t[++cnt] = (lr){x, y};
    fu = get(exc(x, y));
    fv = get(exc(x, y + c));
    for (int i = 0; i < 8; ++i) {
      t1[i] = t2[i] = -1;
      a = x + v1[i], b = y + v2[i];
      tb = b;
      if (b == 0) tb = c;
      if (b > c) tb = 1;
      if (a <= 0 || a > r || !vis[a][tb]) continue;
      if (b > 0) t1[i] = get(exc(a, b));
      if (b <= c) t2[i] = get(exc(a, b + c));
    }
    if (check())
      for (int i = 0; i < 8; ++i) {
        if (t1[i] > 0) f[t1[i]] = fu;
        if (t2[i] > 0) f[t2[i]] = fv;
      }
    vis[x][y] = vis[x][y + c] = 1;
  }
  printf("%d\n", cnt);
  return 0;
}
