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 inf = 1e9;
const double eps = 1e-9;
const double INF = inf;
const double EPS = eps;
int Y[3100][3100], C[3100][3100];
int ep = 1, Sz[310000];
int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Nx[8], Ny[8];
int c, pc;
int n, m, q;
void dfs(int x, int y) {
  C[x][y] = c;
  int nx, ny, i;
  for (i = 0; i < 8; i++) {
    nx = x + dx[i], ny = y + dy[i];
    if (ny < 0) ny = m - 1;
    if (ny == m) ny = 0;
    if (C[nx][ny] == pc) {
      Y[nx][ny] = Y[x][y] + dy[i];
      dfs(nx, ny);
    }
  }
}
void merge(int xf, int yf, int xs, int ys) {
  int i;
  if (Sz[C[xf][yf]] > Sz[C[xs][ys]]) swap(xf, xs), swap(yf, ys);
  Sz[C[xs][ys]] += Sz[C[xf][yf]];
  for (i = 0; i < 3; i++)
    if ((ys + i) % m == (yf + 1) % m) {
      Y[xf][yf] = Y[xs][ys] + i - 1;
      break;
    }
  c = C[xs][ys], pc = C[xf][yf];
  dfs(xf, yf);
}
int main() {
  int i, j, x, y, res = 0;
  scanf("%d%d%d", &n, &m, &q);
  if (m == 1) {
    puts("0");
    return 0;
  }
  while (q > 0) {
    scanf("%d%d", &x, &y), q--, y--;
    for (i = 0; i < 8; i++) {
      Nx[i] = x + dx[i], Ny[i] = y + dy[i];
      if (Ny[i] < 0) Ny[i] = m - 1;
      if (Ny[i] == m) Ny[i] = 0;
    }
    bool fl = 0;
    for (i = 0; i < 8; i++)
      if (C[Nx[i]][Ny[i]])
        for (j = i + 1; j < 8; j++)
          if (C[Nx[i]][Ny[i]] == C[Nx[j]][Ny[j]]) {
            if (Y[Nx[i]][Ny[i]] - dy[i] != Y[Nx[j]][Ny[j]] - dy[j]) {
              fl = 1;
              break;
            }
          }
    if (fl) continue;
    res++;
    Sz[ep] = 1, C[x][y] = ep, Y[x][y] = ep * 10, ep++;
    for (i = 0; i < 8; i++)
      if (C[Nx[i]][Ny[i]] != C[x][y] && C[Nx[i]][Ny[i]] != 0)
        merge(x, y, Nx[i], Ny[i]);
  }
  printf("%d\n", res);
  ;
  return 0;
}
