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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
int D[] = {-1, -1, -1, 0, 1, 1, 1, 0};
int C[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int N = 3010 * 3010 * 3;
int m, n, k, tot, mode;
int id[N];
stack<tuple<int, int, int, int>> cache;
int root(int i) { return id[i] < 0 ? i : root(id[i]); }
void add(int a, int b, int c, int d) {
  int x = (a - 1) * n + b, y = (c - 1) * n + d;
  if (!id[y] || (x = root(x)) == (y = root(y))) return;
  if (mode) cache.push(make_tuple(x, y, id[x], id[y]));
  if (id[x] > id[y]) swap(x, y);
  id[x] += id[y];
  id[y] = x;
}
int main() {
  if (fopen("TASK"
            ".inp",
            "r")) {
    freopen(
        "TASK"
        ".inp",
        "r", stdin);
  }
  m = ({
    int x = 0;
    int c = getchar(), n = 0;
    for (; !isdigit(c); c = getchar()) n = (c == '-');
    for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
    n ? -x : x;
  }),
  n = ({
    int x = 0;
    int c = getchar(), n = 0;
    for (; !isdigit(c); c = getchar()) n = (c == '-');
    for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
    n ? -x : x;
  }),
  k = ({
    int x = 0;
    int c = getchar(), n = 0;
    for (; !isdigit(c); c = getchar()) n = (c == '-');
    for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
    n ? -x : x;
  });
  if (n == 1) return cout << 0, 0;
  n *= 3;
  for (int w = 1, _c = k; w <= _c; ++w) {
    int x = ({
      int x = 0;
      int c = getchar(), n = 0;
      for (; !isdigit(c); c = getchar()) n = (c == '-');
      for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
      n ? -x : x;
    }),
        y = ({
          int x = 0;
          int c = getchar(), n = 0;
          for (; !isdigit(c); c = getchar()) n = (c == '-');
          for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
          n ? -x : x;
        });
    id[(x - 1) * n + y] = id[(x - 1) * n + y + n / 3] =
        id[(x - 1) * n + y + n / 3 * 2] = -1;
    mode = 1;
    for (int p = 0, _c = 2; p <= _c; ++p) {
      for (int t = 0, _c = 7; t <= _c; ++t) {
        int u = x + D[t], v = y + C[t];
        if (1 > u || u > m || 1 > v || v > n) continue;
        add(x, y, u, v);
      }
      y += n / 3;
    }
    y -= n;
    mode = 0;
    if (w == 39) {
    }
    if (root((x - 1) * n + y) == root((x - 1) * n + y + n / 3) ||
        root((x - 1) * n + y + n / 3) == root((x - 1) * n + y + n / 3 * 2)) {
      while (cache.size()) {
        int x, y, u, v;
        tie(x, y, u, v) = cache.top();
        cache.pop();
        id[x] = u;
        id[y] = v;
      }
      id[(x - 1) * n + y] = id[(x - 1) * n + y + n / 3] =
          id[(x - 1) * n + y + n / 3 * 2] = 0;
    } else {
      tot++;
      while (cache.size()) cache.pop();
    }
  }
  cout << tot;
}
