#include <bits/stdc++.h>
using namespace std;
const int N = 20000000;
bool vis[3004][6004];
bool temp[N];
int f[N], p[3004][6004];
int n, row, column;
int dx[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy[] = {1, -1, 0, -1, 1, 0, -1, 1};
int find(int u) {
  if (u == f[u])
    return u;
  else
    return f[u] = find(f[u]);
}
bool check(int x, int y) {
  for (int i = 0; i < 8; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx < 0 || nx >= row) continue;
    ny = (ny + 2 * column) % (2 * column);
    if (!vis[nx][ny]) continue;
    if (temp[find(p[nx][ny])]) return false;
  }
  return true;
}
void test(int a, int b) {
  int fb = find(b);
  temp[fb] = 1;
}
void merge(int a, int b) {
  int fb = find(b);
  temp[fb] = 0;
  f[fb] = a;
}
int main() {
  scanf("%d%d%d", &row, &column, &n);
  for (int i = 0; i < row; i++)
    for (int j = 0; j < 2 * column; j++) {
      p[i][j] = i * 2 * column + j;
      f[p[i][j]] = p[i][j];
    }
  int ans = 0, cnt = 0;
  while (n--) {
    cnt++;
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    if (vis[x][y]) continue;
    vis[x][y] = 1;
    temp[p[x][y]] = 1;
    for (int i = 0; i < 8; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx >= row) continue;
      ny = (ny + 2 * column) % (2 * column);
      if (!vis[nx][ny]) continue;
      test(p[x][y], p[nx][ny]);
    }
    if (check(x, y + column)) {
      ans++;
      for (int i = 0; i < 8; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || nx >= row) continue;
        ny = (ny + 2 * column) % (2 * column);
        if (!vis[nx][ny]) continue;
        merge(p[x][y], p[nx][ny]);
      }
      vis[x][y + column] = 1;
      for (int i = 0; i < 8; i++) {
        int nx = x + dx[i];
        int ny = y + column + dy[i];
        if (nx < 0 || nx >= row) continue;
        ny = (ny + 2 * column) % (2 * column);
        if (!vis[nx][ny]) continue;
        merge(p[x][y + column], p[nx][ny]);
      }
    } else {
      for (int i = 0; i < 8; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || nx >= row) continue;
        ny = (ny + 2 * column) % (2 * column);
        if (!vis[nx][ny]) continue;
        temp[find(p[nx][ny])] = 0;
      }
      vis[x][y] = 0;
    }
    temp[p[x][y]] = 0;
  }
  printf("%d\n", ans);
  return 0;
}
