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;
const int inf = int(1e9);
const double eps = 1e-9;
const double pi = 4 * atan(double(1));
const int N = 3000;
int step, edges;
int _prev[2 * N * N + 10], _rank[2 * N * N + 10];
bool used[N + 10][2 * N + 10];
int use[2 * N * N + 10], num[N + 10][2 * N + 10];
int a[N + 10], b[N + 10];
inline void add(int _a, int _b) {
  a[edges] = _a;
  b[edges++] = _b;
  a[edges] = _b;
  b[edges++] = _a;
}
void dfs(int v) {
  use[v] = step;
  for (int i = 0; i < edges; i++) {
    if (a[i] == v && use[b[i]] != step) {
      dfs(b[i]);
    }
  }
}
int get(int a) {
  if (_prev[a] != a) {
    _prev[a] = get(_prev[a]);
  }
  return _prev[a];
}
inline void merge(int a, int b) {
  a = get(a);
  b = get(b);
  if (a == b) {
    return;
  }
  if (_rank[a] < _rank[b]) {
    swap(a, b);
  }
  _prev[b] = a;
  if (_rank[a] == _rank[b]) {
    _rank[a]++;
  }
}
int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2 * m; j++) {
      _prev[i * 2 * m + j] = i * 2 * m + j;
      _rank[i * 2 * m + j] = 1;
    }
  }
  int ans = 0;
  step = 0;
  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    used[x][y] = used[x][y + m] = true;
    int sz = 0;
    num[x][y] = sz++;
    num[x][y + m] = sz++;
    step++;
    edges = 0;
    for (int j = -1; j <= 1; j++) {
      for (int z = -1; z <= 1; z++) {
        if (j == 0 && z == 0) {
          continue;
        }
        int nx = x + j, ny = y + z;
        if (nx < 0 || nx >= n) {
          continue;
        }
        if (ny < 0) {
          ny += 2 * m;
        }
        if (ny >= 2 * m) {
          ny -= 2 * m;
        }
        if (used[nx][ny]) {
          int p = get(nx * 2 * m + ny);
          if (use[p] != step) {
            use[p] = step;
            num[nx][ny] = sz++;
            add(num[x][y], num[nx][ny]);
          } else {
            add(num[x][y], num[nx][ny]);
          }
        }
      }
    }
    for (int j = -1; j <= 1; j++) {
      for (int z = -1; z <= 1; z++) {
        if (j == 0 && z == 0) {
          continue;
        }
        int nx = x + j, ny = y + m + z;
        if (nx < 0 || nx >= n) {
          continue;
        }
        if (ny < 0) {
          ny += 2 * m;
        }
        if (ny >= 2 * m) {
          ny -= 2 * m;
        }
        if (used[nx][ny]) {
          int p = get(nx * 2 * m + ny);
          if (use[p] != step) {
            use[p] = step;
            num[nx][ny] = sz++;
            add(num[x][y + m], num[nx][ny]);
          } else {
            add(num[x][y + m], num[nx][ny]);
          }
        }
      }
    }
    step++;
    dfs(num[x][y]);
    if (use[num[x][y + m]] == step) {
      used[x][y + m] = used[x][y] = false;
      continue;
    }
    ans++;
    for (int j = -1; j <= 1; j++) {
      for (int z = -1; z <= 1; z++) {
        if (j == 0 && z == 0) {
          continue;
        }
        int nx = x + j, ny = y + z;
        if (nx < 0 || nx >= n) {
          continue;
        }
        if (ny < 0) {
          ny += 2 * m;
        }
        if (ny >= 2 * m) {
          ny -= 2 * m;
        }
        if (used[nx][ny]) {
          merge(x * 2 * m + y, nx * 2 * m + ny);
        }
      }
    }
    for (int j = -1; j <= 1; j++) {
      for (int z = -1; z <= 1; z++) {
        if (j == 0 && z == 0) {
          continue;
        }
        int nx = x + j, ny = y + m + z;
        if (nx < 0 || nx >= n) {
          continue;
        }
        if (ny < 0) {
          ny += 2 * m;
        }
        if (ny >= 2 * m) {
          ny -= 2 * m;
        }
        if (used[nx][ny]) {
          merge(x * 2 * m + y + m, nx * 2 * m + ny);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
