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 fy[9] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int fx[9] = {1, 1, 0, -1, -1, -1, 0, 1, 1};
int Cps, Cp2s;
int bhs[3333][6666];
int fa[11111111];
int zhan[11111111];
int siz[11111111];
int Cp[111], Cp2[111];
int r, c, ans, blocks, c2;
int top(int x) {
  int t;
  for (t = 0; fa[x] != x; t++) {
    zhan[t] = x;
    x = fa[x];
  }
  while (t--) fa[zhan[t]] = x;
  return x;
}
void merge(int a, int b) {
  a = top(a);
  b = top(b);
  if (a == b) return;
  if (siz[b] > siz[a]) swap(a, b);
  fa[b] = a;
  siz[a] += siz[b];
}
void optt(int x, int y) {
  int i, j, gg;
  Cps = 0;
  for (i = 0; i < 8; i++)
    if (x + fx[i] >= 1 && x + fx[i] <= r) {
      gg = y + fy[i];
      if (gg < 1) gg = c2;
      gg = bhs[x + fx[i]][gg];
      if (!gg) continue;
      gg = top(gg);
      for (j = 0; j < Cps; j++)
        if (gg == Cp[j]) break;
      if (j == Cps) Cp[Cps++] = gg;
    }
  Cp2s = 0;
  for (i = 0; i < 8; i++)
    if (x + fx[i] >= 1 && x + fx[i] <= r) {
      gg = y + c + fy[i];
      if (gg > c2) gg = 1;
      gg = bhs[x + fx[i]][gg];
      if (!gg) continue;
      gg = top(gg);
      for (j = 0; j < Cp2s; j++)
        if (gg == Cp2[j]) break;
      if (j == Cp2s) Cp2[Cp2s++] = gg;
    }
  for (i = 0; i < Cps; i++)
    for (j = 0; j < Cp2s; j++)
      if (Cp[i] == Cp2[j]) return;
  ans++;
  bhs[x][y] = ++blocks;
  fa[blocks] = blocks;
  for (i = 0; i < Cps; i++) merge(blocks, Cp[i]);
  bhs[x][y + c] = ++blocks;
  fa[blocks] = blocks;
  for (i = 0; i < Cp2s; i++) merge(blocks, Cp2[i]);
}
int main() {
  int q, i, j;
  scanf("%d%d%d", &r, &c, &q);
  c2 = c << 1;
  if (c == 1) {
    printf("0\n");
    return 0;
  }
  ans = 0;
  blocks = 0;
  while (q--) {
    scanf("%d%d", &i, &j);
    optt(i, j);
  }
  printf("%d\n", ans);
  return 0;
}
