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 = 300 + 5;
int dx[10] = {1, 1, 1, -1, -1, -1, 0, 0};
int dy[10] = {0, 1, -1, 0, 1, -1, 1, -1};
int res, pr, n, m, T, i, te, k, nx, ny, ar;
int x, y;
struct coord {
  int x, y;
};
coord p[N * 2 * N];
bool cmp(const int &a, const int &b) { return (p[a].y < p[b].y); }
int t1;
coord ara[100];
bool mark[N * 2 * N];
int ta, a[100];
int tb, b[100];
int get(int x) {
  if (p[x].x == 0) return 0;
  if (p[x].x == x) return x;
  return p[x].x = get(p[x].x);
}
int main() {
  scanf("%d%d%d", &n, &m, &T);
  for (te = 1; te <= T; ++te) {
    scanf("%d%d", &x, &y);
    ta = 0;
    tb = 0;
    for (k = 0; k < 8; ++k) {
      nx = x + dx[k];
      ny = y + dy[k];
      if (nx >= 1 && nx <= n && ny >= 1 && ny <= 2 * m) {
        ar = get(nx * (2 * m) + ny);
        if (ar != 0) {
          ++ta;
          a[ta] = ar;
        }
      }
    }
    for (k = 0; k < 8; ++k) {
      nx = x + dx[k];
      ny = y + m + dy[k];
      if (nx >= 1 && nx <= n && ny >= 1 && ny <= 2 * m) {
        ar = get(nx * (2 * m) + ny);
        if (ar != 0) {
          ++tb;
          b[tb] = ar;
        }
      }
    }
    for (i = 1; i <= ta; ++i) {
      mark[a[i]] = 1;
    }
    for (i = 1; i <= tb; ++i) {
      if (mark[b[i]]) goto x;
    }
    p[x * (2 * m) + y].x = x * (2 * m) + y;
    p[x * (2 * m) + y].y = 1;
    a[0] = x * (2 * m) + y;
    sort(a, a + ta + 1, cmp);
    for (i = 0; i < ta; ++i) {
      p[a[i]].x = p[a[ta]].x;
      p[a[ta]].y += p[a[i]].y;
    }
    p[x * (2 * m) + y + m].x = x * (2 * m) + y + m;
    p[x * (2 * m) + y + m].y = 1;
    b[0] = x * (2 * m) + y + m;
    sort(b, b + tb + 1, cmp);
    for (i = 0; i < ta; ++i) {
      p[b[i]].x = p[b[tb]].x;
      p[b[tb]].y += p[b[i]].y;
    }
    ++res;
  x:
    for (i = 1; i <= ta; ++i) {
      mark[a[i]] = 0;
    }
  }
  printf("%d\n", res);
  return 0;
}
