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 int MAXK = 3001;
const int MAXN = 300 * 1010;
bitset<MAXK> l_col[MAXN], r_col[MAXN];
int ind[MAXK][MAXK];
bitset<MAXK> lbuf, rbuf;
bool in_range(int l, int s, int r) { return (l <= s && s < r); }
int rang[MAXN], pr[MAXN];
int get_pr(int v) {
  if (pr[v] == v) return v;
  return (pr[v] = get_pr(pr[v]));
}
int merge(int a, int b) {
  a = get_pr(a);
  b = get_pr(b);
  if (a == b) {
    return a;
  }
  if (rang[a] > rang[b]) swap(a, b);
  rang[b] += rang[a];
  pr[a] = b;
  l_col[b] |= l_col[a];
  r_col[b] |= r_col[a];
  return b;
}
int main() {
  int r, c, n;
  cin >> r >> c >> n;
  for (int i = 0; i < n; i++) {
    rang[i] = 1;
    pr[i] = i;
  }
  memset(ind, -1, sizeof ind);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int r1, c1;
    scanf("%i %i", &r1, &c1);
    r1--;
    c1--;
    ind[r1][c1] = i;
    if (c1 == 0) {
      l_col[i][r1] = 1;
      if (r1 > 0) {
        l_col[i][r1 - 1] = 1;
      }
    }
    if (c1 == c - 1) {
      r_col[i][r1] = 1;
      if (r1 > 0) {
        r_col[i][r1 - 1] = 1;
      }
    }
    lbuf.reset();
    rbuf.reset();
    for (int dr = -1; dr <= 1; dr++)
      for (int dc = -1; dc <= 1; dc++) {
        if (in_range(0, dr + r1, r) && in_range(0, dc + c1, c)) {
          int _ind = ind[dr + r1][dc + c1];
          if (_ind != -1) {
            int buf = get_pr(_ind);
            lbuf |= l_col[buf];
            rbuf |= r_col[buf];
          }
        }
      }
    if ((lbuf & rbuf).count() == 0) {
      ans++;
      int cur_ind = i;
      for (int dr = -1; dr <= 1; dr++)
        for (int dc = -1; dc <= 1; dc++) {
          if (in_range(0, dr + r1, r) && in_range(0, dc + c1, c)) {
            int _ind = ind[dr + r1][dc + c1];
            if (_ind != -1) {
              int buf = get_pr(_ind);
              cur_ind = merge(cur_ind, buf);
            }
          }
        }
    } else {
      ind[r1][c1] = -1;
    }
  }
  cout << ans << endl;
  return 0;
}
