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 <iostream>
#include <set>
#include <cstring>
using namespace std;

const int MAX_SZ = 20000000;
const int D = 8;
const int DX[] = {0, 0, -1, 1, -1, 1, -1, 1};
const int DY[] = {-1, 1, 0, 0, -1, 1, 1, -1};

int par[MAX_SZ], rank[MAX_SZ];
bool land[MAX_SZ];

void init()
{
    memset(par, -1, sizeof(par));
    memset(rank, 0, sizeof(rank));
    memset(land, false, sizeof(land));
}

int find(int x)
{
    if (par[x] == -1) return x;
    return par[x] = find(par[x]);
}

void join(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] > rank[y])
        par[y] = x;
    else
    {
        par[x] = y;
        if (rank[x] == rank[y])
            rank[y]++;
    }
}

inline int id(int r, int c)
{
    return r*6001+c;
}

int R, C, N;

inline bool valid(int r, int c)
{
    return (0<=r && r<R && 0<=c && c<2*C);
}

bool place(int r, int c)
{
    set<int> s;
    for (int i=0; i<D; i++)
    {
        int x = r+DX[i], y = c+DY[i];
        if (valid(x,y) && land[id(x,y)])
            s.insert(find(id(x,y)));
    }
    for (int i=0; i<D; i++)
    {
        int x = r+DX[i], y = C+c+DY[i];
        if (valid(x,y) && land[id(x,y)] && s.count(find(id(x,y))))
            return false;
    }
    land[id(r,c)] = land[id(r,C+c)] = true;
    for (int i=0; i<D; i++)
    {
        int x = r+DX[i], y = c+DY[i];
        if (valid(x,y) && land[id(x,y)])
            join(id(r,c), id(x,y));
    }
    for (int i=0; i<D; i++)
    {
        int x = r+DX[i], y = C+c+DY[i];
        if (valid(x,y) && land[id(x,y)])
            join(id(r,C+c), id(x,y));
    }
    return true;
}

int main()
{
    init();
    cin >> R >> C >> N;
    if (C == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    for (int i=0; i<N; i++)
    {
        int r, c;
        cin >> r >> c;
        if (place(r-1, c-1))
            ans++;
    }
    cout << ans << endl;
    return 0;
}
