#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int T, n, r, c, fa[N * N * 2], sz[N * N * 2], stk[N * N * 2], tp, vis[N][N * 2];
int id(int x, int y) { return (x - 1) * c * 2 + y; }
int find(int x) {
  while (x ^ fa[x]) x = fa[x];
  return x;
}
int mrg(int a, int b) {
  if ((a = find(a)) ^ (b = find(b))) {
    if (sz[a] > sz[b]) swap(a, b);
    fa[stk[++tp] = a] = b, sz[b] += sz[a];
    return 1;
  }
  return 0;
}
void undo() {
  int x = stk[tp--];
  sz[fa[x]] -= sz[x], fa[x] = x;
}
int main() {
  for (T = 1; T--;) {
    cin >> r >> c >> n;
    for (int i = (1); i <= (r * c * 2); i++) fa[i] = i, sz[i] = 1;
    for (int i = (1); i <= (r); i++)
      for (int j = (1); j <= (c * 2); j++) vis[i][j] = 0;
    int ans = tp = 0;
    for (int x, y; n--;) {
      scanf("%d%d", &x, &y);
      int cnt = 0;
      for (int k = (0); k <= (1); k++) {
        for (int i = (-1); i <= (1); i++)
          for (int j = (-1); j <= (1); j++) {
            int xx = x + i, yy = y + j;
            if (!yy) yy = c * 2;
            if (yy > c * 2) yy = 1;
            if (xx && xx <= r && yy && yy <= c * 2 && vis[xx][yy])
              cnt += mrg(id(x, y), id(xx, yy));
          }
        vis[x][y] = 1, y += c;
      }
      if (find(id(x, y - c)) == find(id(x, y - c * 2)))
        for (vis[x][y - c] = vis[x][y - c * 2] = 0; cnt--; undo())
          ;
      else
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
