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 <cstdio>
#include <cstring>
#include <iostream>
#define N 3000
#define MAX 30000000
#define pos(x, y) ((x - 1) * (c << 1) + (y))
using namespace std;
struct point {
    int x, y;
    point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
} st[MAX + 5];
int father[MAX + 5], a[N + 5][2 * N + 5], t = 0, r, c, n, step[8][2];
int check(int x, int y) {
    if (x < 1 || x > r || y < 1 || y > (c << 1)) return 0;
    return a[x][y];
}
int getfather(int u) {
    if (u == father[u]) return u;
    int tmp = getfather(father[u]);
    if (father[u] != tmp) st[++t] = point(u, father[u]), father[u] = tmp;
    return tmp;
}
void ui(int u, int v) {
    u = getfather(u), v = getfather(v);
    if (u == v) return;
    st[++t] = point(u, father[u]);
    father[u] = v;
}
void undo() {
    while (st[t].x != 0) {
        father[st[t].x] = st[t].y;
        t--;
    }
    t--;
}
int main() {
    // freopen("325D.in", "r", stdin);
    scanf("%d%d%d", &r, &c, &n);
    for (int i = 1; i <= pos(r, c << 1); i++) father[i] = i;
    int ans = 0;
    step[0][0] = -1, step[0][1] = -1;
    step[1][0] = -1, step[1][1] = 0;
    step[2][0] = -1, step[2][1] = 1;
    step[3][0] = 0, step[3][1] = -1;
    step[4][0] = 0, step[4][1] = 1;
    step[5][0] = 1, step[5][1] = -1;
    step[6][0] = 1, step[6][1] = 0;
    step[7][0] = 1, step[7][1] = 1;
    while (n--) {
        int x, y;
        scanf("%d%d", &x, &y);
        st[t = 1] = point(0, 0);
        a[x][y] = a[x][y + c] = 1;
        for (int i = 0; i < 8; i++)
            if (check(x + step[i][0], y + step[i][1]))
                ui(pos(x, y), pos(x + step[i][0], y + step[i][1]));
        y += c;
        for (int i = 0; i < 8; i++)
            if (check(x + step[i][0], y + step[i][1]))
                ui(pos(x, y), pos(x + step[i][0], y + step[i][1]));
        if (getfather(pos(x, y)) == getfather(pos(x, y - c)))
            undo(), a[x][y] = a[x][y - c] = 0;
        else
            ans++;
    }
    printf("%d\n", ans);
    return 0;
}