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>
inline void in(T &x) {
  x = 0;
  short f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
  x *= f;
}
template <class T>
inline void out(T x, const char c = '\n') {
  static short st[30];
  short m = 0;
  if (x < 0) putchar('-'), x = -x;
  do st[++m] = x % 10, x /= 10;
  while (x);
  while (m) putchar(st[m--] | '0');
  putchar(c);
}
template <class T, class... Args>
inline void in(T &x, Args &...args) {
  in(x);
  in(args...);
}
template <class T, class... Args>
inline void out(const T &x, const Args &...args) {
  out(x, ' ');
  out(args...);
}
template <class T>
inline void prt(T a[], int n) {
  for (register int i = 0; i < n; ++i) out(a[i], ' ');
  putchar('\n');
}
template <class T>
inline void clr(T a[], int n) {
  memset(a, 0, sizeof(T) * n);
}
template <class T>
inline void clr(T *a, T *b) {
  memset(a, 0, sizeof(T) * (b - a));
}
template <class T>
inline bool ckmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool ckmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
namespace MOD_CALC {
const int md = 998244353;
inline int add(const int a, const int b) {
  return a + b >= md ? a + b - md : a + b;
}
inline int sub(const int a, const int b) {
  return a - b < 0 ? a - b + md : a - b;
}
inline int mul(const int a, const int b) { return (long long)a * b % md; }
inline void inc(int &a, const int b) { (a += b) >= md ? a -= md : 0; }
inline void dec(int &a, const int b) { (a -= b) < 0 ? a += md : 0; }
inline int qpow(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1) r = mul(r, a);
  return r;
}
inline int mdinv(const int a) { return qpow(a, md - 2); }
}  // namespace MOD_CALC
using namespace MOD_CALC;
namespace i207M {
int uf[3005 * 6005], sz[3005 * 6005];
inline int ufind(int x) { return x == uf[x] ? x : ufind(uf[x]); }
int n, m, tot;
inline int g(int x, int y) {
  if (x < 1 || x > n) return -1;
  if (y == 0)
    y = 2 * m;
  else if (y == 2 * m + 1)
    y = 1;
  return (x - 1) * m * 2 + y;
}
vector<pair<int *, int>> bak;
inline void upd(int &x, int v) {
  bak.push_back(make_pair(&x, x));
  x = v;
}
void roll() {
  while (!bak.empty()) *bak.back().first = bak.back().second, bak.pop_back();
}
void merge(int x, int y) {
  x = ufind(x), y = ufind(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  upd(uf[y], x);
  upd(sz[x], sz[x] + sz[y]);
}
bool con(int x, int y) { return ufind(x) == ufind(y); }
int xx[] = {-1, -1, 0, 1, 1, 1, 0, -1}, yy[] = {0, 1, 1, 1, 0, -1, -1, -1};
int exi[3005 * 6005];
void add(int x, int y) {
  int k = g(x, y);
  upd(exi[k], 1);
  for (register int dir = 0; dir < 8; ++dir) {
    int t = g(x + xx[dir], y + yy[dir]);
    if (t == -1 || !exi[t]) continue;
    merge(k, t);
  }
}
signed main() {
  int cq, x, y;
  in(n, m, cq);
  tot = n * m * 2;
  for (register int i = 1; i <= tot; ++i) uf[i] = i, sz[i] = 1;
  int ans = 0;
  while (cq--) {
    in(x, y);
    add(x, y);
    add(x, y + m);
    if (con(g(x, y), g(x, y + m)))
      roll();
    else
      ++ans, bak.clear();
  }
  out(ans);
  return 0;
}
}  // namespace i207M
signed main() {
  i207M::main();
  return 0;
}
