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;
inline int Get() {
  int res = 0, q = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') q = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar();
  return res * q;
}
const double eps = 1e-12, pi = M_PI;
const int oo = (int)2e9, mod = (int)1e9 + 7;
const long long INF = (long long)1e17;
const int L = 3000, N = L * L * 2, M = 20;
const int lx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int ly[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
typedef int arr[N + 10];
arr ufs;
int n, m, Rd, T, j, k;
int a[M + 5], b[M + 5];
int v[N + 10];
bool black[L + 10][L + 10];
inline int Pos(int x, int y) { return (x - 1) * m * 2 + y; }
int Find(int x) { return ufs[x] == x ? x : ufs[x] = Find(ufs[x]); }
void Floodfill(int x, int y, int *s) {
  int now = Pos(x, y);
  v[now] = ++Rd, s[s[0] = 1] = now;
  for (int k = (0), end = (7); k <= end; ++k) {
    int xx = x + lx[k], yy = y + ly[k];
    if (xx < 1 || xx > n) continue;
    if (yy > 2 * m)
      yy = 1;
    else if (yy < 1)
      yy = 2 * m;
    int np = Pos(xx, yy);
    if (!ufs[np]) continue;
    int p = Find(np);
    if (v[p] != Rd) v[ufs[np]] = Rd, s[++s[0]] = ufs[np];
  }
}
void Perform(int *s) {
  ufs[s[1]] = s[1];
  for (int i = (2), end = (s[0]); i <= end; ++i) ufs[Find(s[i])] = s[1];
}
int main() {
  scanf(
      "%d"
      "%d"
      "%d"
      "\n",
      &n, &m, &T);
  int ans = 0;
  for (; T--;) {
    scanf(
        "%d"
        "%d"
        "\n",
        &j, &k);
    Floodfill(j, k, a), Floodfill(j, k + m, b);
    ++Rd;
    for (int i = (2), end = (a[0]); i <= end; ++i) v[a[i]] = Rd;
    bool ck = 1;
    for (int i = (2), end = (b[0]); i <= end; ++i)
      if (v[b[i]] == Rd) {
        ck = 0;
        break;
      }
    if (!ck) continue;
    ++ans, Perform(a), Perform(b);
  }
  printf(
      "%d"
      "\n",
      ans);
  return 0;
}
