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 <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

const int MAX_N = 1000000;

int par[MAX_N], rank[MAX_N];

void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rank[i] = 0;
  }
}

int root(int x) {
  return par[x] == x ? x : par[x] = root(par[x]);
}

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y) return;

  if (rank[x] < rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rank[x] == rank[y]) rank[x]++;
  }
}

bool find(int x, int y) {
  return root(x) == root(y);
}

int H, W, N, W2;
int Y[1000010], X[1000010];
int K;

int id[3010][6010];

const int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};

int main() {
  scanf("%d%d%d", &H, &W, &N);
  W2 = W * 2;

  memset(id, -1, sizeof(id));
  rep (i, N) {
    scanf("%d%d", &Y[i], &X[i]);
    --Y[i];
    --X[i];
  }
  init(N * 2);

  int ans = 0;
  rep (i, N) {
    int x = X[i], y = Y[i];

    // Test
    rep (d1, 8) rep (d2, 8) {
      int tx1 = (x + dx[d1] + W2) % W2, ty1 = (y + dy[d1] + W2) % W2;
      int tx2 = (x + dx[d2] + W2) % W2, ty2 = (y + dy[d2] + W2) % W2;
      int k1 = id[ty1][tx1];
      int k2 = id[ty2][tx2];
      if (k1 != -1 && k2 != -1 && find(k1, k2)) goto dmp;
    }

    // Place
    rep (k, 2) {
      id[y][x] = i + k * N;

      rep (d1, 8) rep (d2, 8) {
        int tx1 = (x + dx[d1] + W2) % W2, ty1 = (y + dy[d1] + W2) % W2;
        int k1 = id[ty1][tx1];
        if (k1 != -1) unite(id[y][x], k1);
      }

      x += W;
    }
    ++ans;

    continue;
 dmp:;
  }
  printf("%d\n", ans);
  return 0;
}

