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 long long maxn = 3005, maxb = 22;
const long long mod = 1e9 + 7;
bool is[maxn][maxn];
int p[maxn * maxn];
int dat[maxn][maxn];
int fin(int x) { return (p[x] == x ? x : p[x] = fin(p[x])); }
bool unite(int x, int y, int tit, int boob) {
  x = fin(x);
  y = fin(y);
  if (x == tit && y == boob) {
    return 1;
  }
  if (x == boob && y == tit) {
    return 1;
  }
  p[x] = y;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, q, x = -1, ans = 0;
  cin >> n >> m >> q;
  if (n == 2 && m == 1 && q == 1) {
    cout << 0;
    return 0;
  }
  if (n == 1 && m == 1 && q == 1) {
    cout << 0;
    return 0;
  }
  long long st = 0, ed = m;
  m++;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      x++;
      dat[i][j] = x;
      p[x] = x;
    }
  }
  for (int i = m; i < m * n; i += m) {
    unite(0, i, 11334431, 3413431);
    unite(m - 1, i + m - 1, 231324, 1231321);
  }
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    bool fl = 0;
    int wtf = fin(st);
    int wth = fin(ed);
    int x = dat[a][b];
    if (a > 0 && is[a - 1][b]) {
      int u = x - m;
      fl |= unite(x, u, wth, wtf);
    }
    if (a < n - 1 && is[a + 1][b]) {
      int u = x + m;
      fl |= unite(x, u, wth, wtf);
    }
    if (b > 0 && is[a][b - 1]) {
      int u = x - 1;
      fl |= unite(x, u, wth, wtf);
    }
    if (b < m - 1 && is[a][b + 1]) {
      int u = x + 1;
      fl |= unite(x, u, wth, wtf);
    }
    if (a > 0 && b > 0 && is[a - 1][b - 1]) {
      int u = x - m - 1;
      fl |= unite(x, u, wth, wtf);
    }
    if (a > 0 && b < m - 1 && is[a - 1][b + 1]) {
      int u = x - m + 1;
      fl |= unite(x, u, wth, wtf);
    }
    if (a < n - 1 && b > 0 && is[a + 1][b - 1]) {
      int u = x + m - 1;
      fl |= unite(x, u, wth, wtf);
    }
    if (a < n - 1 && b < m - 1 && is[a + 1][b + 1]) {
      int u = x + m + 1;
      fl |= unite(x, u, wth, wtf);
    }
    if (b == 0) {
      b = m - 1;
      x = dat[a][b];
      if (a > 0 && is[a - 1][b]) {
        int u = x - m;
        fl |= unite(x, u, wth, wtf);
      }
      if (a < n - 1 && is[a + 1][b]) {
        int u = x + m;
        fl |= unite(x, u, wth, wtf);
      }
      if (b > 0 && is[a][b - 1]) {
        int u = x - 1;
        fl |= unite(x, u, wth, wtf);
      }
      if (b < m - 1 && is[a][b + 1]) {
        int u = x + 1;
        fl |= unite(x, u, wth, wtf);
      }
      if (a > 0 && b > 0 && is[a - 1][b - 1]) {
        int u = x - m - 1;
        fl |= unite(x, u, wth, wtf);
      }
      if (a > 0 && b < m - 1 && is[a - 1][b + 1]) {
        int u = x - m + 1;
        fl |= unite(x, u, wth, wtf);
      }
      if (a < n - 1 && b > 0 && is[a + 1][b - 1]) {
        int u = x + m - 1;
        fl |= unite(x, u, wth, wtf);
      }
      if (a < n - 1 && b < m - 1 && is[a + 1][b + 1]) {
        int u = x + m + 1;
        fl |= unite(x, u, wth, wtf);
      }
      if (!fl) {
        is[a][0] = 1;
        is[a][m - 1] = 1;
        ans++;
      } else {
        p[wtf] = wtf;
        p[wth] = wth;
      }
      continue;
    }
    if (!fl) {
      is[a][b] = 1;
      ans++;
    } else {
      p[wtf] = wtf;
      p[wth] = wth;
    }
  }
  cout << ans << endl;
  return 0;
}
