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;
int R, C, N, x, y, Ans;
int Parent[3333 * 3333];
bool Land[3333][3333];
int Len[3333 * 3333];
int Find(int x) { return Parent[x] < 0 ? x : Parent[x] = Find(Parent[x]); }
void Union(int n1, int n2) {
  int r1 = Find(n1), r2 = Find(n2);
  if (r1 == r2) return;
  if (Parent[r1] < Parent[r2]) {
    Parent[r1] += Parent[r2];
    Parent[r2] = r1;
  } else {
    Parent[r2] += Parent[r1];
    Parent[r1] = r2;
  }
}
bool add(int x, int y) {
  int ly = (y == 1) ? C : (y - 1);
  int ry = (y >= C) ? y - C + 1 : (y + 1);
  for (int lx = max(0, x - 1); lx <= min(R, x + 1); ++lx)
    for (int rx = max(0, x - 1); rx <= min(R, x + 1); ++rx)
      if (Land[lx][ly] && Land[rx][ry] &&
          Find(lx * 3333 + ly) == Find(rx * 3333 + ry) &&
          (Len[Find(lx * 3333 + ly)] > C ||
           Len[Find(lx * 3333 + ly)] == C && (y == 1 || y == C + 1) ||
           Len[Find(lx * 3333 + ly)] == C - 1 && y == C))
        return false;
  int len = y;
  for (int lx = max(1, x - 1); lx <= min(R, x + 1); ++lx)
    if (Land[lx][ly]) {
      Union(lx * 3333 + ly, x * 3333 + y);
      len = max(len, Len[Find(lx * 3333 + ly)]);
    }
  for (int rx = max(1, x - 1); rx <= min(R, x + 1); ++rx)
    if (Land[rx][ry]) {
      Union(rx * 3333 + ry, x * 3333 + y);
      len = max(len, Len[Find(rx * 3333 + ry)]);
    }
  Land[x][y] = true;
  Len[Find(x * 3333 + y)] = len;
  return true;
}
int main() {
  scanf("%d%d%d", &R, &C, &N);
  memset(Parent, -1, sizeof(Parent));
  while (N--) {
    scanf("%d%d", &x, &y);
    if (add(x, y)) {
      ++Ans;
      if (y == 1) add(x, C + 1);
    }
    for (int i = 1; i <= R; ++i) {
      for (int j = 1; j <= C + 1; ++j)
        printf("(%d)(%d)%-6d", (int)Land[i][j], Len[i * 3333 + j],
               Find(i * 3333 + j));
      printf("\n");
    }
  }
  printf("%d\n", Ans);
  return 0;
}
