#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 * 2;
int m, n, k, tot, mode;
int to[N];
stack<tuple<int, int, int, int>> cache;
int root(int i) { return to[i] < 0 ? i : root(to[i]); }
void add(int a, int b, int c, int d) {
  int x = (a - 1) * n + b, y = (c - 1) * n + d;
  if (!to[y] || !to[x] || (x = root(x)) == (y = root(y))) return;
  if (mode) cache.push(make_tuple(x, y, to[x], to[y]));
  if (to[x] > to[y]) swap(x, y);
  to[x] += to[y];
  to[y] = x;
}
int main() {
  if (fopen("TASK"
            ".inp",
            "r")) {
    freopen(
        "TASK"
        ".inp",
        "r", stdin);
    freopen(
        "TASK"
        ".out",
        "w", stdout);
  }
  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 += n;
  while (k--) {
    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;
        });
    to[(x - 1) * n + y] = to[(x - 1) * n + y + n / 2] = -1;
    mode = 1;
    for (int p = 0, _c = 1; p <= _c; ++p) {
      for (int t = 0, _c = 7; t <= _c; ++t) {
        int u = x + D[t], v = y + C[t];
        if (v < 1) v = n;
        if (v > n) v = 1;
        if (1 > u || u > m || 1 > v || v > n) continue;
        add(x, y, u, v);
      }
      y += n / 2;
    }
    y -= n;
    mode = 0;
    if (root((x - 1) * n + y) == root((x - 1) * n + y + n / 2)) {
      while (cache.size()) {
        int x, y, u, v;
        tie(x, y, u, v) = cache.top();
        cache.pop();
        to[x] = u;
        to[y] = v;
      }
      to[(x - 1) * n + y] = to[(x - 1) * n + y + n / 2] = 0;
    } else {
      tot++;
      while (cache.size()) cache.pop();
    }
  }
  cout << tot;
}
