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 Read() {
  char c;
  while (c = getchar(), (c != '-') && (c < '0' || c > '9'))
    ;
  bool neg = (c == '-');
  int ret = (neg ? 0 : c - 48);
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48;
  return neg ? -ret : ret;
}
const int MAXN = 3005, dx[8] = {-1, 0, 1, 0, 0, -1, 0, 1},
          dy[8] = {-1, -1, -1, -1, 1, 1, 1, 1};
vector<pair<int, int> > bak;
int R, C, N, ans, cnt, fa[MAXN * MAXN * 2];
bitset<MAXN * 2> a[MAXN];
int FindSet(int x) {
  return fa[x] ? bak.push_back(make_pair(x, fa[x])), fa[x] = FindSet(fa[x]),
                                                     fa[x] : x;
}
void Ins(int x, int y) {
  a[x][y] = 1;
  int id = (x - 1) * 2 * C + y;
  for (int k = 0; k <= 7; k++) {
    int nx = x + dx[k], ny = y + dy[k];
    if (!ny) ny = 2 * C;
    if (ny > 2 * C) ny = 1;
    if (nx && nx <= R && a[nx][ny]) {
      int u = FindSet(id), v = FindSet((nx - 1) * 2 * C + ny);
      if (u != v) bak.push_back(make_pair(u, 0)), fa[u] = v;
    }
  }
}
int main() {
  scanf("%d%d%d", &R, &C, &N);
  for (int i = 1; i <= N; i++) {
    int x = Read(), y = Read();
    bak.clear();
    Ins(x, y), Ins(x, y + C);
    if (FindSet((x - 1) * 2 * C + y) == FindSet((x - 1) * 2 * C + y + C)) {
      a[x][y] = a[x][y + C] = 0;
      for (int j = (int)bak.size() - 1; j >= 0; j--)
        fa[bak[j].first] = bak[j].second;
    } else
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}
