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 N = 18000003, dx[] = {0, 0, 1, 1, 1, -1, -1, -1},
          dy[] = {-1, 1, -1, 0, 1, -1, 0, 1};
template <typename T>
void read(T &x) {
  int ch = getchar();
  x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) return a = b, 1;
  return 0;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) return a = b, 1;
  return 0;
}
int r, c, n, m, fa[N], h[N], ans;
vector<pair<int *, int> > cha;
bool vis[3003][6003];
int id(int x, int y) { return 2 * x * c + y; }
int get(int x) {
  while (x != fa[x]) x = fa[x];
  return x;
}
void comb(int x, int y) {
  x = get(x);
  y = get(y);
  if (x == y) return;
  if (h[x] < h[y]) swap(x, y);
  cha.push_back(make_pair(fa + y, fa[y]));
  fa[y] = x;
  if (h[x] == h[y]) {
    cha.push_back(make_pair(h + x, h[x]));
    ++h[x];
  }
}
void work(int x, int y) {
  int u = id(x, y);
  vis[x][y] = true;
  for (int d = 0; d < 8; ++d) {
    int nx = x + dx[d], ny = y + dy[d];
    if (ny < 0) ny += c << 1;
    if (ny >= (c << 1)) ny -= c << 1;
    if (nx >= 0 && nx < r && vis[nx][ny]) comb(u, id(nx, ny));
  }
}
int main() {
  read(r);
  read(c);
  read(m);
  n = r * c << 1;
  for (int i = 0; i < n; ++i) fa[i] = i;
  while (m--) {
    int x, y;
    read(x);
    read(y);
    --x;
    --y;
    cha.clear();
    work(x, y);
    work(x, y + c);
    if (get(id(x, y)) == get(id(x, y + c))) {
      vis[x][y] = vis[x][y + c] = false;
      for (auto u : cha) *u.first = u.second;
    } else
      ++ans;
  }
  printf("%d\n", ans);
}
