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 <typename t>
inline void read(t &x) {
  x = 0;
  char c = getchar(), f = 0;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = 1;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
}
namespace DSU {
int fa[9000005], sz[9000005], tp;
pair<int, int> st[9000005];
inline void addnd(int id) {
  fa[id] = id, sz[id] = 1, st[++tp] = make_pair(id, 0);
}
inline int getf(int x) { return fa[x] == x ? x : getf(fa[x]); }
inline void mrg(int x, int y) {
  if (!fa[x] || !fa[y])
    return;
  else
    x = getf(x), y = getf(y);
  if (x == y)
    return;
  else if (sz[x] > sz[y])
    swap(x, y);
  st[++tp] = make_pair(x, y), sz[y] += sz[x], fa[x] = y;
}
inline void pop() {
  int x = st[tp].first, y = st[tp--].second;
  if (y)
    fa[x] = x, sz[y] -= sz[x];
  else
    fa[x] = sz[x] = 0;
}
}  // namespace DSU
using namespace DSU;
int n, m, Q, res = 0;
const int dx[8] = {0, 0, -1, 1, -1, -1, 1, 1},
          dy[8] = {-1, 1, 0, 0, -1, 1, -1, 1};
inline int id(int x, int y) { return (x - 1) * m + y; }
inline void ins(int x, int y) {
  int xy = id(x, y);
  addnd(xy);
  for (int i = 0; i < 8; i++) {
    int a = x + dx[i], b = y + dy[i], ab = id(a, b);
    if (a > 0 && a <= n && b > 0 && b <= m) mrg(xy, ab);
  }
  if (y == 1)
    mrg(n * m + 1, xy);
  else if (y == m)
    mrg(n * m + 2, xy);
}
inline char chk(int x, int y) {
  int nw = tp;
  ins(x, y);
  if (y == 1) ins(x, m);
  if (getf(n * m + 1) != getf(n * m + 2)) return 1;
  {
    while (tp > nw) pop();
  }
  return 0;
}
int main() {
  read(n), read(m), m++, read(Q), addnd(n * m + 1), addnd(n * m + 2);
  for (int x, y; Q--;) read(x), read(y), res += chk(x, y);
  return printf("%d\n", res), 0;
}
