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