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 dx[8] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[8] = {0, 0, 1, -1, -1, 1, 1, -1};
int T, r, c, n, fa[21000000], rk[21000000], num[21000000], lim;
bool vis[3100][6100];
char Getchar() {
  static char now[1 << 20], *S, *T;
  if (T == S) {
    T = (S = now) + fread(now, 1, 1 << 20, stdin);
    if (T == S) return EOF;
  }
  return *S++;
}
int read() {
  int x = 0, f = 1;
  char ch = Getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = Getchar();
  }
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = Getchar();
  return x * f;
}
int findset(int x) {
  if (x != fa[x]) fa[x] = findset(fa[x]);
  return fa[x];
}
void Union2(int x, int y) {
  x = findset(x);
  y = findset(y);
  if (rk[x] < rk[y])
    fa[x] = y, rk[y] += rk[x];
  else
    fa[y] = x, rk[x] += rk[y];
}
int hs(int x, int y) {
  if (y == 0) return 0;
  if (y == 2 * c + 1) return lim;
  return (x - 1) * 2 * c + y;
}
void Union(int x, int y) {
  vis[x][y] = true;
  int nx, ny;
  for (int k = 0; k < 8; k++) {
    nx = x + dx[k];
    ny = y + dy[k];
    if (nx < 1 || nx > r) continue;
    if (vis[nx][ny] || ny < 1 || ny > c * 2) Union2(hs(x, y), hs(nx, ny));
  }
}
bool check(int t, int x, int y) {
  int nx, ny, tmp;
  bool f0 = false, f1 = false;
  for (int k = 0; k < 8; k++) {
    nx = x + dx[k];
    ny = y + dy[k];
    if (nx < 1 || nx > r) continue;
    if (vis[nx][ny] || ny < 1 || ny > c * 2) {
      tmp = findset(hs(nx, ny));
      if (tmp == findset(0))
        f0 = true;
      else if (tmp == findset(lim))
        f1 = true;
      else
        num[tmp] = t;
    }
  }
  if (f0 && f1) return false;
  y += c;
  bool g0 = false, g1 = false, flag = false;
  for (int k = 0; k < 8; k++) {
    nx = x + dx[k];
    ny = y + dy[k];
    if (nx < 1 || nx > r) continue;
    if (vis[nx][ny] || ny < 1 || ny > c * 2) {
      tmp = findset(hs(nx, ny));
      if (tmp == findset(0))
        g0 = true;
      else if (tmp == findset(lim))
        g1 = true;
      else if (num[tmp] == t)
        flag = true;
    }
  }
  if (g0 && g1) return false;
  if (flag && (f0 && g1 || f1 && g0)) return false;
  return true;
}
int main() {
  r = read();
  c = read();
  n = read();
  lim = hs(r, 2 * c) + 1;
  for (int i = 0; i <= lim; i++) {
    fa[i] = i;
    rk[i] = 1;
    num[i] = 0;
  }
  int x, y, ans = 0;
  for (int i = 1; i <= n; i++) {
    x = read();
    y = read();
    if (check(i, x, y)) {
      Union(x, y);
      ans++;
      Union(x, y + c);
    }
  }
  printf("%d\n", ans);
  return 0;
}
