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 a1[8] = {-1, -1, -1, 0, 0, 1, 1, 1},
          a2[8] = {1, -1, 0, 1, -1, 1, -1, 0};
struct ww {
  int x, y;
} g[3000000];
int i, j, k, n, m, x, y, r, an, K;
int id[3010][3010 * 3], f[3010 * 3010 * 3];
bool h[3010][3010 * 3];
int get(int x) {
  g[++r] = (ww){x, f[x]};
  return f[x] == x ? x : f[x] = get(f[x]);
}
inline void Do(int x, int y) {
  int i;
  for (i = 0; i <= 7; i++) {
    int X = x + a1[i], Y = y + a2[i];
    if (X && Y && X <= n && Y <= m * 3 && h[X][Y]) {
      int A = get(id[X][Y]), B = get(id[x][y]);
      g[++r] = (ww){B, f[B]};
      f[B] = A;
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m * 3; j++) id[i][j] = ++k;
  for (i = 1; i <= k; i++) f[i] = i;
  for (i = 1; i <= K; i++) {
    scanf("%d%d", &x, &y);
    r = 0;
    h[x][y] = h[x][y + m] = h[x][y + m * 2] = 1;
    Do(x, y), Do(x, y + m), Do(x, y + m * 2);
    if (r > 3000000) printf("shit\n");
    if (get(id[x][y]) == get(id[x][y + m * 2])) {
      h[x][y] = h[x][y + m] = h[x][y + m * 2] = 0;
      for (; r; r--) {
        ww A = g[r];
        f[A.x] = A.y;
      }
    } else
      an++;
  }
  printf("%d\n", an);
  return 0;
}
