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;

#define CH(x) {&(x), (x)}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int, int> pii;

int n, m;
pii par[3005][6005];
int sz[3005][6005];
int alive[3005][6005];

template<class T>
inline auto S(T& x, pii a) -> decltype(x[0][0])& {
	return x[a.first][a.second];
}

pii e(pii a) {
	while (a != S(par, a))
		a = S(par, a);
	return a;
}

basic_string<pair<int*, int>> changes;

void spoji(pii a, pii b) {
	a = e(a);
	b = e(b);
	if (a == b)
		return;
	if (S(sz, a) < S(sz, b))
		swap(a, b);

	changes += CH(S(par, b).first);
	changes += CH(S(par, b).second);
	changes += CH(S(sz, a));

	S(par, b) = a;
	S(sz, a) += S(sz, b);
}

void flag() {
	changes += pair<int*, int>(nullptr, 0);
}

void rollback() {
	while (1) {
		auto [x, y] = changes.back();
		changes.pop_back();
		if (!x) return;
		*x = y;
	}
}

void dodaj(int u, int v) {
	changes += CH(alive[u][v]);
	changes += CH(par[u][v].first);
	changes += CH(par[u][v].second);
	changes += CH(sz[u][v]);
	alive[u][v] = 1;
	par[u][v] = {u, v};
	sz[u][v] = 1;
	for (int x=-1; x<=1; x++)
		for (int y=-1; y<=1; y++) {
			if (x == 0 && y == 0)
				continue;
			int p = u+x;
			int q = v+y;
			if (p < 0 || p >= n || q < 0 || q >= 2*m)
				continue;
			if (alive[p][q])
				spoji({u, v}, {p, q});
		}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int t, z=0;
	cin >> n >> m >> t;
	while (t--) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		flag();
		dodaj(x, y);
		dodaj(x, y+m);
		if (e({x, y}) == e({x, y+m})) {
			rollback();
		} else {
			z++;
			changes.clear();
		}
	}
	cout << z << '\n';
}