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(unsigned long long(new char)));
  }
} static __init__;
const int maxn = 3010;
const int maxm = maxn * maxn;
int n, m, q;
int getd(pair<int, int> p) { return p.first * m - p.second; }
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);
}
int fa[maxm];
pair<int, int> vl[maxm], vr[maxm];
int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }
bool inr(pair<int, int> p, int x) { return p.first <= x && x <= p.second; }
bool inter(pair<int, int> x, pair<int, int> y) {
  return inr(x, y.first) || inr(x, y.second) || inr(y, x.first) ||
         inr(y, x.second);
}
void update(pair<int, int> &x, pair<int, int> y) {
  chkmin(x.first, y.first);
  chkmax(x.second, y.second);
}
bool merge(int x, int y) {
  int f1 = getfa(x), f2 = getfa(y);
  if (f1 == f2) return true;
  if (inter(vl[f1], vr[f2]) || inter(vr[f1], vl[f2])) return false;
  fa[f1] = f2;
  update(vl[f2], vl[f1]);
  update(vr[f2], vr[f1]);
  return true;
}
bitset<maxn> vis[maxn];
bool leg(pair<int, int> p) {
  return inr(pair<int, int>(1, n + 1), p.first) &&
         inr(pair<int, int>(1, m), p.second) && vis[p.first][p.second];
}
int ans;
void solve() {
  pair<int, int> p;
  cin >> p.first >> p.second;
  swap(p.first, p.second);
  set<int> st;
  int f = getfa(getd(p));
  st.insert(f);
  for (pair<int, int> t : mov) {
    pair<int, int> q = p + t;
    if (leg(q)) st.insert(getfa(getd(q)));
  }
  pair<int, int> cl, cr;
  cl = cr = pair<int, int>(INT_MAX, INT_MIN);
  for (int x : st) {
    update(cl, vl[x]);
    update(cr, vr[x]);
  }
  if (inter(cl, cr)) return;
  if (p.first != 1) {
    for (int x : st) merge(x, f);
    vis[p.first][p.second] = true;
    ans++;
    return;
  }
  p.first = n + 1;
  set<int> st2;
  int f2 = getfa(getd(p));
  st2.insert(f2);
  for (pair<int, int> t : mov) {
    pair<int, int> q = p + t;
    if (leg(q)) st2.insert(getfa(getd(q)));
  }
  bool flag = false;
  for (int x : st2)
    if (st.count(x)) {
      flag = true;
      break;
    }
  if (flag) {
    for (int x : st2) {
      update(cl, vl[x]);
      update(cr, vr[x]);
      st.insert(x);
    }
    st2.clear();
  } else {
    cl = cr = pair<int, int>(INT_MAX, INT_MIN);
    for (int x : st2) {
      update(cl, vl[x]);
      update(cr, vr[x]);
    }
  }
  if (inter(cl, cr)) return;
  for (int x : st) merge(x, f);
  for (int x : st2) merge(x, f2);
  vis[1][p.second] = vis[n + 1][p.second] = true;
  ans++;
}
int main() {
  cin >> n >> m >> q;
  swap(n, m);
  for (int i = 1; i <= (n + 1); i++)
    for (int j = 1; j <= (m); j++) {
      int k = getd(pair<int, int>(i, j));
      fa[k] = k;
      vl[k] = vr[k] = pair<int, int>(INT_MAX, INT_MIN);
    }
  for (int j = 1; j <= (m); j++) {
    int k = getd(pair<int, int>(1, j));
    vl[k] = pair<int, int>(j, j);
    k = getd(pair<int, int>(n + 1, j));
    vr[k] = pair<int, int>(j, j);
  }
  while (q--) solve();
  cout << ans << '\n';
  return 0;
}
