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 _prev[N * N + 10], _rank[N * N + 10], min_y[N * N + 10], max_y[N * N + 10];
bool used[N + 10][N + 10];
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]) {
    _prev[b] = a;
    _rank[a]++;
    min_y[a] = min(min_y[a], min_y[b]);
    max_y[a] = max(max_y[a], max_y[b]);
    return;
  }
  if (_rank[a] > _rank[b]) {
    _prev[b] = a;
    min_y[a] = min(min_y[a], min_y[b]);
    max_y[a] = max(max_y[a], max_y[b]);
    return;
  }
  _prev[a] = b;
  min_y[b] = min(min_y[b], min_y[a]);
  max_y[b] = max(max_y[b], max_y[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 < m; j++) {
      _prev[i * m + j] = i * m + j;
      _rank[i * m + j] = 1;
      min_y[i * m + j] = max_y[i * m + j] = j;
    }
  }
  int ans = 0;
  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    int y1 = y, y2 = y;
    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 || ny < 0 || ny >= m) {
          continue;
        }
        if (used[nx][ny]) {
          int p = get(nx * m + ny);
          y1 = min(y1, min_y[p]);
          y2 = max(y2, max_y[p]);
        }
      }
    }
    if (y1 == 0 && y2 == m - 1) {
      continue;
    }
    ans++;
    used[x][y] = true;
    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 || ny < 0 || ny >= m) {
          continue;
        }
        if (used[nx][ny]) {
          merge(x * m + y, nx * m + ny);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
