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 MAXN = 300 * 1010;
const int MAXK = 3010;
int ind[MAXK][MAXK * 2];
int r, c, n;
int pr[2 * MAXN], rang[2 * MAXN];
int in_range(int l, int s, int r) { return (l <= s && s < r); }
int get_pr(int v) {
  if (v == pr[v]) return v;
  return (pr[v] = get_pr(pr[v]));
}
int merge(int a, int b) {
  a = get_pr(a);
  b = get_pr(b);
  if (a == b) {
    return a;
  }
  if (rang[a] > rang[b]) swap(a, b);
  rang[b] += rang[a];
  pr[a] = b;
  return b;
}
int merge_all(int r1, int c1) {
  vector<int> cur;
  for (int dr = -1; dr <= 1; dr++)
    for (int dc = -1; dc <= 1; dc++) {
      if (in_range(0, r1 + dr, r) &&
          ind[r1 + dr][(c1 + dc + 2 * c) % (2 * c)] != -1) {
        int buf = get_pr(ind[r1 + dr][(c1 + dc + 2 * c) % (2 * c)]);
        cur.push_back(buf);
      }
    }
  assert(cur.size() > 0);
  int buf = cur[0];
  for (int i : cur) {
    buf = merge(buf, i);
  }
  return buf;
}
int col[2 * MAXN];
int ind_col = 0;
int check(int r1, int c1) {
  vector<int> cur;
  for (int dr = -1; dr <= 1; dr++)
    for (int dc = -1; dc <= 1; dc++) {
      if (in_range(0, r1 + dr, r) &&
          ind[r1 + dr][(c1 + dc + 2 * c) % (2 * c)] != -1) {
        int buf = get_pr(ind[r1 + dr][(c1 + dc + 2 * c) % (2 * c)]);
        cur.push_back(buf);
      }
    }
  sort(cur.begin(), cur.end());
  cur.resize(distance(cur.begin(), unique(cur.begin(), cur.end())));
  for (int ind : cur) {
    if (col[ind] == ind_col) return 0;
    col[ind] = ind_col;
  }
  return 1;
}
int main() {
  cin >> r >> c >> n;
  if (c == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < 2 * n; i++) {
    pr[i] = i;
    rang[i] = 1;
  }
  int ans = 0;
  memset(ind, -1, sizeof ind);
  for (int i = 0; i < n; i++) {
    int r1, c1;
    cin >> r1 >> c1;
    r1--;
    c1--;
    ind_col++;
    assert(check(r1, c1));
    if (check(r1, c1 + c)) {
      ans++;
      ind[r1][c1] = i;
      ind[r1][c1 + c] = i + n;
      merge_all(r1, c1);
      merge_all(r1, c1 + c);
    }
  }
  cout << ans << endl;
  return 0;
}
