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;
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;
}
