#include <bits/stdc++.h>
using namespace std;
const int maxn = 18000000 + 5;
int r, c, m;
int s, t;
int f[maxn];
bool vis[maxn];
void init() {
  scanf("%d%d%d", &r, &c, &m);
  for (int i = 1; i <= 2 * r * c; ++i) f[i] = i;
}
int encode(int x, int y) {
  if (x < 1 || x > r) return -1;
  if (y == 0) y = c * 2;
  if (y == c * 2 + 1) y = 1;
  return (x - 1) * c * 2 + y;
}
int find(int x) {
  if (f[x] == x) return x;
  return f[x] = find(f[x]);
}
void merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return;
  f[fx] = fy;
}
int solve(int x, int y) {
  if (c == 1) return 0;
  int p;
  bool flag = false;
  set<int> left, right;
  set<int>::iterator it;
  for (int i = -1; i <= 1; ++i)
    for (int j = -1; j <= 1; ++j) {
      if (i == 0 && j == 0) continue;
      p = encode(x + i, y + j);
      if (p < 0 || !vis[p]) continue;
      left.insert(find(p));
    }
  for (int i = -1; i <= 1; ++i)
    for (int j = -1; j <= 1; ++j) {
      if (i == 0 && j == 0) continue;
      p = encode(x + i, y + c + j);
      if (p < 0 || !vis[p]) continue;
      if (left.count(find(p))) flag = true;
      right.insert(find(p));
    }
  if (flag) return 0;
  p = encode(x, y);
  vis[p] = true;
  for (it = left.begin(); it != left.end(); ++it) merge(p, *it);
  p = encode(x, y + c);
  vis[p] = true;
  for (it = right.begin(); it != right.end(); ++it) merge(p, *it);
  return 1;
}
int main() {
  init();
  int res = 0;
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    res += solve(x, y);
  }
  printf("%d\n", res);
  return 0;
}
