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;

typedef __int64 LL;
typedef pair<int, int> PII;

const int MAXN = 3e5 + 5;
const int MX = 3e3 + 5;
const int INF = 0x3f3f3f3f;

int r, c, n;
int fa[MX * MX * 2];
int L[MX * MX * 2], R[MX * MX * 2];
bool G[MX][MX * 2];

struct Data{
    int id, L, R, fa;
};
stack<Data> stk;

inline int id(int x, int y) { return (x - 1) * c * 2 + y; }

void I() {
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= 2 * c; j++) {
            int k = id(i, j);
            fa[k] = k; L[k] = R[k] = j;
            G[i][j] = false;
        }
    }
}

int F(int x) { return x == fa[x] ? x : fa[x] = F(fa[x]); }

void U(int a, int b) {
    a = F(a), b = F(b);
    if (a == b) return;
    stk.push(Data{a, L[a], R[a], fa[a]});
    stk.push(Data{b, L[b], R[b], fa[b]});
    fa[b] = a;
    L[a] = L[b] = min(L[a], L[b]);
    R[a] = R[b] = max(R[a], R[b]);
}

int DIR[][2] = {{ -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};

bool check(int x, int y) {
    while(!stk.empty()) stk.pop();
    int a[2] = { F(id(x, y)), F(id(x, y + c)) };
    int p[2][2] = {{x, y}, {x, y + c}};

    for (int z = 0; z < 2; z++) {
        for (int i = 0; i < 8; i++) {
            int xx = p[z][0] + DIR[i][0];
            int yy = p[z][1] + DIR[i][1];
            if (xx < 1 || xx > r) continue;
            if (yy < 1 || yy > 2 * c) continue;
            if (G[xx][yy] == false) continue;
            int k = F(id(xx, yy));
            U(a[z], k);
        }
    }
    
    if(L[F(a[0])] == 1 && R[F(a[0])] == 2 * c) {
        while(!stk.empty()) {
            Data tp = stk.top(); stk.pop();
            L[tp.id] = tp.L;
            R[tp.id] = tp.R;
            fa[tp.id] = tp.fa;
        }
        return false;
    }
    G[x][y] = G[x][y + c] = true;
    return true;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    int x, y, ans = 0;
    scanf("%d %d %d", &r, &c, &n); I();
    while (n --) {
        scanf("%d %d", &x, &y);
        if (check(x, y)) ans ++;
    }
    if(c == 1) ans = 0;
    cout << ans << endl;
    return 0;
}
