#include <bits/stdc++.h>
using namespace std;
const int N = 3030, NN = N * N * 2;
const int vx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int vy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int n, m, q, ans, v[NN], vflag, ufs[NN], ar[N], ap, br[N], bp;
int gef(int d) { return (ufs[d] == d) ? d : ufs[d] = gef(ufs[d]); }
void merge(int a, int b) {
  if (v[b] == vflag) return;
  ufs[gef(b)] = gef(a);
  v[b] = vflag;
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  if (m == 1) {
    printf("0\n");
    return 0;
  }
  for (int x0, y0, x1, y1, d0, d1; q--;) {
    scanf("%d%d", &x0, &y0);
    x1 = x0, y1 = y0 + m;
    d0 = ((((x0)-1) * (m + m)) + y0), ufs[d0] = d0;
    d1 = ((((x1)-1) * (m + m)) + y1), ufs[d1] = d1;
    ap = bp = 0;
    for (int l = 0, nx, ny; l < 8; l++) {
      nx = x0 + vx[l], ny = y0 + vy[l];
      if (1 <= nx && nx <= n) {
        if (!ny) ny = m + m;
        if (ufs[((((nx)-1) * (m + m)) + ny)])
          ar[++ap] = gef(((((nx)-1) * (m + m)) + ny));
      }
      nx = x1 + vx[l], ny = y1 + vy[l];
      if (1 <= nx && nx <= n) {
        if (ny > m + m) ny = 1;
        if (ufs[((((nx)-1) * (m + m)) + ny)])
          br[++bp] = gef(((((nx)-1) * (m + m)) + ny));
      }
    }
    bool okay = 1;
    vflag++;
    for (int i = 1; i <= ap; i++) v[ar[i]] = vflag;
    for (int i = 1; i <= bp; i++)
      if (v[br[i]] == vflag) {
        okay = 0;
        break;
      }
    if (okay) {
      vflag++;
      for (int i = 1; i <= ap; i++) merge(d0, ar[i]);
      for (int i = 1; i <= bp; i++) merge(d1, br[i]);
      ans++;
    } else {
      ufs[d0] = ufs[d1] = 0;
    }
  }
  printf("%d\n", ans);
}
