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>
inline void read(int &x) { scanf("%d", &x); }
inline void read(long long &x) { scanf("%I64d", &x); }
inline void read(double &x) { scanf("%lf", &x); }
inline void read(long double &x) {
  double tmp;
  read(tmp);
  x = tmp;
}
template <class T>
inline void read(T *a, int n) {
  for (long long i = (0); i < (n); ++i) read(a[i]);
}
inline void write(int x) { printf("%d", x); }
inline void write(long long x) { printf("%I64d", x); }
inline void write(double x) { printf("%.10lf", x); }
inline void write(long double x) { printf("%.10lf", (double)x); }
template <class T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
template <class T>
inline void writeln(T *a, int n) {
  for (long long i = (0); i < (n); ++i) write(a[i]);
  putchar('\n');
}
template <class T>
inline void writelnln(T *a, int n) {
  for (long long i = (0); i < (n); ++i) writeln(a[i]);
}
int n, m, q;
int _fa[20000000];
const int dx[8] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dy[8] = {1, -1, 1, 0, -1, 1, 0, -1};
bool in[3008][6008];
inline int fa(int x) {
  if (x == _fa[x])
    return x;
  else
    return _fa[x] = fa(_fa[x]);
}
inline int hash(int x, int y) { return x * 6008 + y; }
inline void un(int x1, int y1, int x2, int y2) {
  int h1 = hash(x1, y1), h2 = hash(x2, y2);
  _fa[fa(h1)] = fa(h2);
}
inline bool _con(int x1, int y1, int x2, int y2) {
  if (y1 <= 0) y1 = 2 * m;
  if (y1 > 2 * m) y1 = 1;
  if (y2 <= 0) y2 = 2 * m;
  if (y2 > 2 * m) y2 = 1;
  return in[x1][y1] && in[x2][y2] && fa(hash(x1, y1)) == fa(hash(x2, y2));
}
inline void _add(int x, int y) {
  for (long long d = (0); d < (8); ++d) {
    int tx = x + dx[d], ty = y + dy[d];
    if (ty <= 0) ty = 2 * m;
    if (ty > 2 * m) ty = 1;
    if (in[tx][ty]) un(x, y, tx, ty);
  }
  in[x][y] = 1;
}
inline bool con(int x1, int y1, int x2, int y2) {
  for (long long d1 = (0); d1 < (8); ++d1)
    for (long long d2 = (0); d2 < (8); ++d2)
      if (_con(x1 + dx[d1], y1 + dy[d1], x2 + dx[d2], y2 + dy[d2])) return true;
  return false;
}
inline bool add(int x, int y) {
  if (con(x, y, x, y + m)) return false;
  _add(x, y);
  _add(x, y + m);
  return true;
}
int main() {
  memset(in, 0, sizeof(in));
  read(n);
  read(m);
  read(q);
  if (m == 1) {
    writeln(0);
    return 0;
  }
  for (long long i = (0); i < (20000000); ++i) _fa[i] = i;
  int ans = 0;
  while (q--) {
    int x, y;
    read(x);
    read(y);
    ans += add(x, y);
  }
  writeln(ans);
  return 0;
}
