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 bool getmin(T *a, const T &b) {
  if (b < *a) {
    *a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool getmax(T *a, const T &b) {
  if (b > *a) {
    *a = b;
    return true;
  }
  return false;
}
template <class T>
inline void read(T *a) {
  char c;
  while (isspace(c = getchar())) {
  }
  bool flag = 0;
  if (c == '-')
    flag = 1, *a = 0;
  else
    *a = c - 48;
  while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
  if (flag) *a = -*a;
}
const int mo = 1000000007;
template <class T>
T pow(T a, T b, int c = mo) {
  T res = 1;
  for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % mo)
    if (b & i) res = 1LL * res * a % mo;
  return res;
}
const int C = 3010, R = 3010, N = C * R * 2;
const int x_[8] = {-1, -1, -1, 0, 0, 1, 1, 1},
          y_[8] = {1, -1, 0, 1, -1, 1, -1, 0};
int n, m, k, root[N] = {}, ans = 0, g1[C] = {}, g2[C] = {}, tot = 0;
bool del[R][C + C] = {};
inline int f(int a, int b) { return (a - 1) * (m + m) + b; }
int get_root(int r) {
  ++tot, g1[tot] = r, g2[tot] = root[r];
  if (r != root[r]) root[r] = get_root(root[r]);
  return root[r];
}
void merge(int u, int v) {
  u = get_root(u), v = get_root(v);
  ++tot, g1[tot] = u, g2[tot] = root[u];
  root[u] = v;
}
void work(int x, int y) {
  int s = f(x, y);
  for (int j = 0; j < 8; ++j) {
    int x1 = x + x_[j], y1 = y + y_[j];
    if (y1 == 0) y1 = m + m;
    if (y1 > m + m) y1 = 1;
    if (del[x1][y1]) merge(s, f(x1, y1));
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n * (m + m); ++i) root[i] = i;
  for (int i = 1, x = 0, y = 0; i <= k; ++i) {
    tot = 0;
    scanf("%d%d", &x, &y);
    del[x][y] = del[x][y + m] = true;
    work(x, y);
    work(x, y + m);
    if (get_root(f(x, y)) == get_root(f(x, y + m))) {
      del[x][y] = del[x][y + m] = false;
      for (int j = tot; j >= 1; --j) root[g1[j]] = g2[j];
    } else
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}
