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;
template <class T>
bool chkmin(T &x, T y) {
  return y < x ? (x = y, true) : false;
}
template <class T>
bool chkmax(T &x, T y) {
  return y > x ? (x = y, true) : false;
}
struct __init {
  __init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(16);
    cout << fixed;
    srand(time(0) ^ unsigned long long(new char));
  }
} static __init__;
const int maxn = 1e5 + 10;
int r, c, n;
pair<int, int> p[maxn];
class Hash_pii {
 public:
  unsigned long long operator()(pair<int, int> p) const {
    return unsigned long long(p.first) << 32 ^ p.second;
  }
};
unordered_map<pair<int, int>, int, Hash_pii> mp;
bitset<3010> flag, con;
int fa[maxn];
bitset<3010> mask[maxn][2];
int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }
void merge(int x, int y) {
  int f1 = getfa(x), f2 = getfa(y);
  if (f1 == f2) return;
  fa[f1] = f2;
  mask[f2][0] |= mask[f1][0];
  mask[f2][1] |= mask[f1][1];
}
const vector<pair<int, int> > mov = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1},
                                     {0, 1},   {1, -1}, {1, 0},  {1, 1}};
pair<int, int> operator+(pair<int, int> x, pair<int, int> y) {
  return pair<int, int>(x.first + y.first, x.second + y.second);
}
bool imp(pair<int, int> p) {
  return (p.second == 1 || p.second == c + 1) && 1 <= p.first && p.first <= r;
}
bool alive[maxn];
int main() {
  cin >> r >> c >> n;
  for (int i = 1; i <= (n); i++) cin >> p[i].first >> p[i].second;
  for (int i = 1; i <= (n); i++) {
    if (imp(p[i])) continue;
    mp[p[i]] = i;
    fa[i] = i;
    for (pair<int, int> t : mov) {
      pair<int, int> q = p[i] + t;
      if (imp(q)) mask[i][q.second != 1][q.first] = 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= (n); i++) {
    if (imp(p[i])) {
      if (!con[p[i].first]) {
        alive[i] = true;
        ans++;
        flag[p[i].first] = 1;
      }
    } else {
      bitset<3010> tmp[2];
      memcpy(tmp, mask[getfa(i)], sizeof tmp);
      for (pair<int, int> t : mov) {
        pair<int, int> q = p[i] + t;
        auto it = mp.find(q);
        if (it != mp.end() && alive[it->second]) {
          tmp[0] |= mask[getfa(it->second)][0];
          tmp[1] |= mask[getfa(it->second)][1];
        }
      }
      bitset<3010> ts = tmp[0] & tmp[1];
      if ((ts & flag).any()) continue;
      alive[i] = true;
      ans++;
      con |= ts;
      for (pair<int, int> t : mov) {
        pair<int, int> q = p[i] + t;
        auto it = mp.find(q);
        if (it != mp.end() && alive[it->second]) {
          merge(i, it->second);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
