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 = 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;
bool has_s[NN], has_t[NN];
int gef(int d) { return (ufs[d] == d) ? d : ufs[d] = gef(ufs[d]); }
bool unable(int a[], int p, int d) {
  bool have_s = has_s[d], have_t = has_t[d];
  for (int i = 1; i <= p; i++) {
    have_s |= has_s[a[i]];
    have_t |= has_t[a[i]];
  }
  return have_s && have_t;
}
void merge(int a, int b) {
  if (v[b] == vflag)
    return;
  else
    v[b] = vflag;
  int ra = gef(a), rb = gef(b);
  ufs[rb] = ra;
  has_s[ra] |= has_s[rb];
  has_t[ra] |= has_t[rb];
}
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;
    if (y0 == 1) has_s[d0] = 1;
    if (y0 == m) has_t[d1] = 1;
    ap = bp = 0;
    for (int l = 0, nx, ny; l < 8; l++) {
      if ((nx = x0 + vx[l], ((1 <= nx) && (nx <= n))) &&
          (ny = y0 + vy[l], ((1 <= ny) && (ny <= m + m))) &&
          ufs[((((nx)-1) * (m + m)) + ny)] != 0) {
        ar[++ap] = gef(((((nx)-1) * (m + m)) + ny));
      }
      if ((nx = x1 + vx[l], ((1 <= nx) && (nx <= n))) &&
          (ny = y1 + vy[l], ((1 <= ny) && (ny <= m + m))) &&
          ufs[((((nx)-1) * (m + m)) + ny)] != 0) {
        br[++bp] = gef(((((nx)-1) * (m + m)) + ny));
      }
    }
    bool dont_lk = 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) {
        dont_lk = 0;
        break;
      }
    if (dont_lk) {
      if (unable(ar, ap, d0) || unable(br, bp, d1)) {
        ufs[d0] = has_s[d0] = 0;
        ufs[d1] = has_t[d1] = 0;
      } else {
        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 {
      ar[++ap] = d1;
      for (; bp; bp--)
        if (v[br[bp]] != vflag) ar[++ap] = br[bp];
      if (unable(ar, ap, d0)) {
        ufs[d0] = has_s[d0] = 0;
        ufs[d1] = has_t[d1] = 0;
      } else {
        vflag++;
        for (int i = 1; i <= ap; i++) merge(d0, ar[i]);
        ans++;
      }
    }
  }
  printf("%d\n", ans);
}
