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 T min(T &a, T &b) {
  return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
  return a > b ? a : b;
}
template <class T>
void read(T &x) {
  char ch;
  while ((ch = getchar()) && !isdigit(ch))
    ;
  x = ch - '0';
  while ((ch = getchar()) && isdigit(ch)) x = x * 10 + ch - '0';
}
struct point {
  int x, y;
  point() {}
  point(int _x, int _y) : x(_x), y(_y) {}
};
const int N = 3010;
const int u[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int v[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int fa[N * N * 3], n, m, K, cnt, vis[N][N << 1], ans;
pair<int, int> Stack[N << 3];
int g_f(int x) {
  if (fa[x] == x) return x;
  int y = g_f(fa[x]);
  Stack[++cnt] = make_pair(x, fa[x]);
  fa[x] = y;
}
void Insert(int x, int y) {
  for (int _ = 0; _ <= 7; _++) {
    int xx = x + u[_], yy = y + v[_];
    if (xx == 0 || xx == n + 1) continue;
    if (yy == 0) yy = m << 1;
    if (yy > (m << 1)) yy = 1;
    if (!vis[xx][yy]) continue;
    int p = g_f(((x - 1) * (m << 1) + y)), q = g_f(((xx - 1) * (m << 1) + yy));
    Stack[++cnt] = make_pair(p, fa[p]);
    fa[p] = q;
  }
  vis[x][y] = 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  int x, y;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m << 1; j++)
      fa[((i - 1) * (m << 1) + j)] = ((i - 1) * (m << 1) + j);
  for (int i = 1; i <= K; i++) {
    scanf("%d%d", &x, &y);
    Insert(x, y);
    Insert(x, y + m);
    if (g_f(((x - 1) * (m << 1) + y)) == g_f(((x - 1) * (m << 1) + y + m)))
      while (cnt--) fa[Stack[cnt].first] = Stack[cnt].second;
    else
      ans++;
    cnt = 0;
  }
  printf("%d\n", ans);
}
