#include <bits/stdc++.h>
using namespace std;
struct pr {
  int x, y;
  pr() {
    this->x = 0;
    this->y = 0;
  }
  pr(int x, int y) {
    this->x = x;
    this->y = y;
  }
};
int r, c, n;
int fa[5050 * 5050 * 2];
bool G[5050][5050 * 2];
stack<pr> stk;
int sign(int x, int y) { return (x - 1) * c * 2 + y; }
void I() {
  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= 2 * c; j++) {
      int k = sign(i, j);
      fa[k] = k;
      G[i][j] = false;
    }
  }
}
int F(int x) {
  if (x == fa[x]) return x;
  stk.push(pr(x, fa[x]));
  return fa[x] = F(fa[x]);
}
void U(int a, int b) {
  a = F(a), b = F(b);
  if (a == b) return;
  stk.push(pr(a, fa[a]));
  stk.push(pr(b, fa[b]));
  fa[b] = a;
}
int DIR[][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1},
                {0, 1},   {1, -1}, {1, 0},  {1, 1}};
bool check(int x, int y) {
  while (!stk.empty()) stk.pop();
  int p[2][2] = {{x, y}, {x, y + c}};
  for (int z = 0; z < 2; z++) {
    for (int i = 0; i < 8; i++) {
      int xx = p[z][0] + DIR[i][0];
      int yy = p[z][1] + DIR[i][1];
      if (xx < 1 || xx > r) continue;
      if (yy < 1)
        yy = 2 * c;
      else if (yy > 2 * c)
        yy = 1;
      if (G[xx][yy] == false) continue;
      U(sign(p[z][0], p[z][1]), sign(xx, yy));
    }
  }
  if (F(sign(p[0][0], p[0][1])) == F(sign(p[1][0], p[1][1]))) {
    while (!stk.empty()) {
      pr tp = stk.top();
      stk.pop();
      fa[tp.x] = tp.y;
    }
    return false;
  }
  G[x][y] = G[x][y + c] = true;
  return true;
}
int main() {
  int x, y, ans = 0;
  cin >> r >> c >> n;
  I();
  while (n--) {
    cin >> x >> y;
    if (check(x, y)) ans++;
  }
  if (c <= 1)
    cout << 0 << endl;
  else
    cout << ans << endl;
  return 0;
}
