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 MN = 3010;

int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

int R, C, N;
int fa[2 * MN * MN];
void init() {
    for(int i = 0; i < 2 * MN * MN; i++) fa[i] = i;
}
int f(int u) {
    if(fa[u] == u) return u;
    else return fa[u] = f(fa[u]);
}
void mrg(int u, int v) {
    u = f(u);
    v = f(v);
    fa[v] = u;
}
int g(int r, int c) {
    return r * (2 * C) + c;
}
int G[MN][MN << 1];
vector<int> adj[2 * MN * MN];
int vis[2 * MN * MN];

bool dfs(int u, int d) {
    if(u == d) return true;
    vis[u] = 1;

    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(vis[v]) continue;
        if(dfs(v, d)) return true;
    }
    return false;
}

int main() {
    scanf("%d %d %d", &R, &C, &N);

    init();
    int ans = 0;
    for(int i = 0; i < N; i++) {
        int r, c; scanf("%d %d", &r, &c);
        r--; c--;

        vector<int> V;
        V.push_back(f(g(r, c)));
        V.push_back(f(g(r, C + c)));
        G[r][c] = 1;
        G[r][C + c] = 1;
        for(int j = 0; j < 8; j++) {
            int nr = r + dy[j];
            int nc = c + dx[j];
            if(nr < 0 || R <= nr || nc < 0 || 2 * C <= nc) continue;
            if(!G[nr][nc]) continue;

            adj[ f(g(r, c)) ].push_back(f(g(nr, nc)));
            adj[ f(g(nr, nc)) ].push_back(f(g(r, c)));
            V.push_back(f(g(nr, nc)));
        }
        for(int j = 0; j < 8; j++) {
            int nr = r + dy[j];
            int nc = C + c + dx[j];
            if(nr < 0 || R <= nr || nc < 0 || 2 * C <= nc) continue;
            if(!G[nr][nc]) continue;

            adj[ f(g(r, C + c)) ].push_back(f(g(nr, nc)));
            adj[ f(g(nr, nc)) ].push_back(f(g(r, C + c)));
            V.push_back(f(g(nr, nc)));
        }
        bool res = dfs(f(g(r, c)), f(g(r, C + c)));
        vis[ f(g(1, 0)) ] = 0;
        for(int j = 0; j < V.size(); j++) {
            adj[ V[j] ].clear();
            vis[ V[j] ] = 0;
        }
        if(res) {
            G[r][c] = 0;
            G[r][C + c] = 0;
            continue;
        }
        ans++;
        for(int j = 0; j < 8; j++) {
            int nr = r + dy[j];
            int nc = c + dx[j];
            if(nr < 0 || R <= nr || nc < 0 || 2 * C <= nc) continue;
            if(!G[nr][nc]) continue;
            mrg(g(r, c), g(nr, nc));
        }
        for(int j = 0; j < 8; j++) {
            int nr = r + dy[j];
            int nc = C + c + dx[j];
            if(nr < 0 || R <= nr || nc < 0 || 2 * C <= nc) continue;
            if(!G[nr][nc]) continue;
            mrg(g(r, C + c), g(nr, nc));
        }
    }
    printf("%d", ans);
}
