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;
int dr[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};
int root[20000000], I[100], J[100];
int find_root(int u) {
  if (u == root[u]) return u;
  return root[u] = find_root(root[u]);
}
int main() {
  int r, c, rr, cc, i, j, k, u, uu, v, R, C, N, Q, src, tar, res, n, m, ok, ok1,
      ok2;
  scanf("%d %d %d ", &R, &C, &Q);
  if (C == 1) {
    puts("0");
    return 0;
  }
  N = R * C * 2;
  src = N;
  tar = N + 1;
  res = 0;
  for (i = 0; i < N; i++) root[i] = -1;
  for (i = 0; i < Q; i++) {
    scanf("%d %d ", &r, &c);
    r--;
    c--;
    u = r * C * 2 + c;
    n = 0;
    for (j = 0; j < 8; j++) {
      rr = r + dr[j];
      cc = c + dc[j];
      v = rr * C * 2 + cc;
      if ((rr < 0 || cc < 0 || rr >= R || cc >= 2 * C)) {
        if (cc < 0) I[n++] = src;
      } else {
        if (root[v] != -1) {
          v = find_root(v);
          I[n++] = v;
        }
      }
    }
    uu = r * C * 2 + c + C;
    m = 0;
    for (j = 0; j < 8; j++) {
      rr = r + dr[j];
      cc = c + C + dc[j];
      v = rr * C * 2 + cc;
      if ((rr < 0 || cc < 0 || rr >= R || cc >= 2 * C)) {
        if (cc >= 2 * C) J[m++] = tar;
      } else {
        if (root[v] != -1) {
          v = find_root(v);
          J[m++] = v;
        }
      }
    }
    sort(I, I + n);
    n = unique(I, I + n) - I;
    sort(J, J + m);
    m = unique(J, J + m) - J;
    ok = 0;
    for (j = 0; j < n; j++)
      for (k = 0; k < m; k++)
        if (I[j] == J[k]) ok = 1;
    if (ok) {
      for (k = 0; k < m; k++) I[n + k] = J[k];
      n += m;
      sort(I, I + n);
      n = unique(I, I + n) - I;
      ok = 0;
      for (j = 0; j < n; j++)
        if (I[j] == src)
          ok |= 1;
        else if (I[j] == tar)
          ok |= 2;
      if (ok != 3) {
        if (ok == 1) {
          for (j = 0; j < n; j++) root[I[j]] = src;
          root[u] = src;
          root[uu] = src;
        } else if (ok == 2) {
          for (j = 0; j < n; j++) root[I[j]] = tar;
          root[u] = tar;
          root[uu] = tar;
        } else {
          for (j = 0; j < n; j++) root[I[j]] = u;
          root[uu] = u;
        }
        res++;
      }
    } else {
      if (n + m == 0) {
        root[u] = u;
        root[uu] = uu;
        res++;
        continue;
      }
      ok1 = 0;
      for (j = 0; j < n; j++)
        if (I[j] == src)
          ok1 |= 1;
        else if (I[j] == tar)
          ok1 |= 2;
      ok2 = 0;
      for (k = 0; k < m; k++)
        if (J[k] == src)
          ok2 |= 1;
        else if (J[k] == tar)
          ok2 |= 2;
      if (ok1 != 3 && ok2 != 3) {
        if (ok1 == 1) {
          for (j = 0; j < n; j++) root[I[j]] = src;
          root[u] = src;
        } else if (ok1 == 2) {
          for (j = 0; j < n; j++) root[I[j]] = tar;
          root[u] = tar;
        } else {
          for (j = 0; j < n; j++) root[I[j]] = u;
          root[u] = u;
        }
        if (ok2 == 1) {
          for (k = 0; k < m; k++) root[J[k]] = src;
          root[uu] = src;
        } else if (ok2 == 2) {
          for (k = 0; k < m; k++) root[J[k]] = tar;
          root[uu] = tar;
        } else {
          for (k = 0; k < m; k++) root[J[k]] = uu;
          root[uu] = uu;
        }
        res++;
      }
    }
  }
  printf("%d\n", res);
  return 0;
}
