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 <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <bitset>
#include <cstdio>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAXN = 3030;
const int MAXP = 3030*3030;

int dad[MAXP];
int id1[MAXP];
int id2[MAXP];
bitset<MAXN> b1[MAXN], b2[MAXN];
bitset<MAXN> t1, t2, t;

int bio[MAXP], cookie;
bool black[MAXN][MAXN];

int findset(int x) {
  return x == dad[x] ? x : dad[x] = findset(dad[x]);
}

void merge(int x, int y) {
  x = findset(x), y = findset(y);
  dad[x] = y;
  if (id1[y] && id1[x]) b1[id1[y]] |= b1[id1[x]];
  if (id2[y] && id2[x]) b2[id2[y]] |= b2[id2[x]];
  if (!id1[y]) id1[y] = id1[x];
  if (!id2[y]) id2[y] = id2[x];
}

int main(void) {
  int r, c, q;
  scanf("%d %d %d", &r, &c, &q);
  REP(i, r) REP(j, c) {
    int k = i*c + j;
    dad[k] = k;
    id1[k] = id2[k] = 0;
  }
  
  int ans = 0;
  REP(i, q) {
    int x, y;
    scanf("%d %d", &x, &y); --x, --y;
    
    cookie++;
    t1.reset(), t2.reset();
    if (y == 0) t1.set(x);
    if (y == c-1) t2.set(x);

    vector<int> v;
    for (int dx = -1; dx <= 1; ++dx)
      for (int dy = -1; dy <= 1; ++dy) {
        int X = x + dx, Y = y + dy;
        if (X < 0 || X >= r || Y < 0 || Y >= c) continue;
        if (!black[X][Y]) continue;

        int fs = findset(X*c + Y);
        if (bio[fs] == cookie) continue;

        v.push_back(fs);
        bio[fs] = cookie;
        if (id1[fs]) t1 |= b1[id1[fs]];
        if (id2[fs]) t2 |= b2[id2[fs]];
      }

    t = t1 & t2;
    if (t.count()) continue;
    t = t1 & (t2>>1);
    if (t.count()) continue;
    t = t1 & (t2<<1);
    if (t.count()) continue;

    black[x][y] = true;
    int k = x*c + y;
    if (y == 0) {
      id1[k] = x+1;
      b1[id1[k]].set(x);
    }
    if (y == c-1) {
      id2[k] = x+1;
      b2[id2[k]].set(x);
    }

    ans++;
    for (int x: v)
      merge(x, k);
  }
  
  printf("%d\n", ans);
  
  return 0;
}
