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;
int fa[9090909 * 2];
int ud[9090909 * 2];
int os[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
inline int enc(int x, int y) { return x * 6006 + y; }
int gf(int a) {
  int f = a;
  while (fa[f] != f) f = fa[f];
  while (a != f) {
    int o = fa[a];
    fa[a] = f;
    a = o;
  }
  return f;
}
void merge(int a, int b) {
  a = gf(a), b = gf(b);
  fa[a] = b;
}
int s0[8], s1[8], n0, n1;
int main() {
  int r, c, n;
  scanf("%d%d%d", &r, &c, &n);
  for (int i = 0; i < 9090909 * 2; i++) fa[i] = i;
  for (int i = 0; i <= r + 1; i++)
    ud[enc(i, 0)] = 1, ud[enc(i, 2 * c + 1)] = 1, fa[enc(i, 0)] = 0,
              fa[enc(i, 2 * c + 1)] = 2 * c + 1;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (ud[enc(x, y)]) continue;
    int f0 = gf(0), f1 = gf(2 * c + 1), en = enc(x, y);
    n0 = n1 = 0;
    for (int j = 0; j < 8; j++) {
      int dx = x + os[j][0];
      int dy = y + os[j][1];
      int ed = enc(dx, dy);
      if (ud[ed]) s0[n0++] = gf(ed);
      ed = enc(dx, dy + c);
      if (ud[ed]) s1[n1++] = gf(ed);
    }
    int ic = 0;
    for (int j = 0; j < n0 && !ic; j++)
      for (int k = 0; k < n1 && !ic; k++)
        if (s0[j] == s1[k]) ic = 1;
    if (ic) {
      int h0 = 0, h1 = 0;
      for (int j = 0; j < n0; j++) h0 |= s0[j] == f0, h1 |= s0[j] == f1;
      for (int j = 0; j < n1; j++) h0 |= s1[j] == f0, h1 |= s1[j] == f1;
      if (h0 && h1) continue;
    }
    for (int j = 0; j < n0; j++) merge(s0[j], en);
    ud[en] = 1;
    en = enc(x, y + c);
    for (int j = 0; j < n1; j++) merge(s1[j], en);
    ud[en] = 1;
    ans++;
  }
  printf("%d", ans);
  return 0;
}
