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;
int dsu[2 * 3000 * 3000 + 10];
int rnk[2 * 3000 * 3000 + 10];
vector<int> mod, pos;
int Find(int x) {
  if (dsu[x] == x) return x;
  return Find(dsu[x]);
}
void Union(int x, int y) {
  x = Find(x);
  y = Find(y);
  if (rnk[x] < rnk[y]) {
    mod.push_back(dsu[x]);
    pos.push_back(x);
    dsu[x] = y;
  } else {
    mod.push_back(dsu[y]);
    pos.push_back(y);
    dsu[y] = x;
  }
  if (rnk[x] == rnk[y]) rnk[x]++, rnk[y]++;
}
void Rollback(int s) {
  while ((int)mod.size() > s) {
    dsu[pos.back()] = mod.back();
    pos.pop_back();
    mod.pop_back();
  }
}
int usd[3100][2 * 3100];
int dx[] = {1, 0, -1, 1, 0, -1, 1, -1};
int dy[] = {1, 1, 1, -1, -1, -1, 0, 0};
int main() {
  ios::sync_with_stdio(0);
  int r, c, n;
  cin >> r >> c >> n;
  if (c == 1) {
    cout << "0\n";
    return 0;
  }
  for (int i = 0; i < 2 * 3000 * 3000 + 10; ++i) dsu[i] = i, rnk[i] = 1;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    usd[x][y] = 1;
    usd[x][y + c] = 1;
    int st = mod.size();
    vector<int> cx, cy;
    for (int k = 0; k < 8; ++k) {
      int nx = x + dx[k];
      int ny = y + dy[k];
      ny = (ny + 2 * c) % (2 * c);
      if (0 <= nx && nx < r) {
        if (usd[nx][ny]) cx.push_back(nx), cy.push_back(ny);
        if (usd[nx][ny]) Union(2 * x * c + y, 2 * nx * c + ny);
      }
    }
    y += c;
    for (int k = 0; k < 8; ++k) {
      int nx = x + dx[k];
      int ny = y + dy[k];
      ny = (ny + c + c) % (2 * c);
      if (0 <= nx && nx < r) {
        if (usd[nx][ny]) Union(2 * x * c + y, 2 * nx * c + ny);
      }
    }
    int fl = 1;
    for (int j = 0; j < (int)cx.size(); ++j) {
      if (Find(2 * cx[j] * c + cy[j]) == Find(2 * cx[j] * c + c + cy[j]))
        fl = 0;
    }
    ans += fl;
    y -= c;
    if (!fl) Rollback(st), usd[x][y] = 0, usd[x][y + c] = 0;
  }
  cout << ans << endl;
  return 0;
}
