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;
using pii = pair<int, int>;
const int MAX_N = 3e3 + 5;
int diri[8] = {0, 0, -1, -1, -1, 1, 1, 1};
int dirj[8] = {-1, 1, -1, 0, 1, -1, 0, 1};
int r, c, n;
bool inBounds(pii pos) {
  return pos.first >= 0 && pos.first < r && pos.second >= 0 &&
         pos.second < 2 * c;
}
bool Active[MAX_N][2 * MAX_N];
pii Parent[MAX_N][2 * MAX_N];
int Rank[MAX_N][2 * MAX_N];
void initDSU() {
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < 2 * c; j++) {
      Active[i][j] = false;
      Rank[i][j] = 0;
      Parent[i][j] = {i, j};
    }
  }
}
pii findSet(pii a) {
  if (Parent[a.first][a.second] == a) return a;
  return findSet(Parent[a.first][a.second]);
}
bool sameSet(pii a, pii b) { return findSet(a) == findSet(b); }
void unionSet(pii a, pii b) {
  if (sameSet(a, b)) return;
  a = findSet(a);
  b = findSet(b);
  if (Rank[a.first][a.second] < Rank[b.first][b.second]) {
    swap(a, b);
  }
  Parent[b.first][b.second] = a;
  Rank[a.first][a.second]++;
}
pii fixPos(pii pos) { return {pos.first, (pos.second + 2 * c) % (2 * c)}; }
bool canUnion(pii a, pii b) {
  set<pii> AdjSets;
  for (int k = 0; k < 8; k++) {
    pii pos;
    pos.first = a.first + diri[k];
    pos.second = a.second + dirj[k];
    pos = fixPos(pos);
    if (inBounds(pos) && Active[pos.first][pos.second]) {
      AdjSets.insert(findSet(pos));
    }
  }
  for (int k = 0; k < 8; k++) {
    pii pos;
    pos.first = b.first + diri[k];
    pos.second = b.second + dirj[k];
    pos = fixPos(pos);
    if (inBounds(pos) && Active[pos.first][pos.second] &&
        AdjSets.count(findSet(pos))) {
      return false;
      ;
    }
  }
  return true;
}
void addNode(pii a) {
  Active[a.first][a.second] = true;
  for (int k = 0; k < 8; k++) {
    pii pos;
    pos.first = a.first + diri[k];
    pos.second = a.second + dirj[k];
    pos = fixPos(pos);
    if (inBounds(pos) && Active[pos.first][pos.second]) {
      unionSet(a, pos);
    }
  }
}
int main() {
  scanf("%d%d%d", &r, &c, &n);
  initDSU();
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    pii pos, clone;
    scanf("%d%d", &pos.first, &pos.second);
    pos.first--, pos.second--;
    if (c == 1) {
      continue;
    }
    clone = pos;
    clone.second += c;
    if (canUnion(pos, clone) && canUnion(clone, pos)) {
      cnt++;
      addNode(pos);
      addNode(clone);
    }
  }
  printf("%d", cnt);
  return 0;
}
