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<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int SIZEN=300010,SIZER=3010,SIZERC=3000*6000+10;
int R,C,N;
int ans=0;
int ufs[SIZERC]={0};
int hash(int i,int j){
	return i*C*2+j;
}
int grand(int x){
	//cout<<x<<" "<<ufs[x]<<endl;
	return ufs[x]==-1?x:ufs[x]=grand(ufs[x]);
}
void merge(int ga,int gb){//������
	if(ga==gb) return;
	ufs[ga]=gb;
}
int dx[]={0,0,1,-1,1,-1,1,-1},dy[]={1,-1,0,0,1,-1,-1,1};
int vis[SIZERC]={0};
bool ground[SIZER][2*SIZER]={0};
bool legal(int &i,int &j){
	if(i<0||i>=R) return false;
	if(j>=2*C) j-=2*C;
	else if(j<0) j+=2*C;
	return true;
}
void reclamate(int x,int y){
	//cout<<x<<" "<<y<<":"<<endl;
	static int timer=0;
	timer++;
	static vector<int> now1,now2;
	now1.clear();now2.clear();
	for(int d=0;d<8;d++){
		int x1=x+dx[d],y1=y+dy[d];
		if(!legal(x1,y1)) continue;
		if(!ground[x1][y1]) continue;
		//cout<<x1<<" "<<y1<<endl;
		int k=grand(hash(x1,y1));
		vis[k]=timer;
		now1.push_back(k);
	}
	for(int d=0;d<8;d++){
		int x1=x+dx[d],y1=y+C+dy[d];
		if(!legal(x1,y1)) continue;
		if(!ground[x1][y1]) continue;
		int k=grand(hash(x1,y1));
		if(vis[k]==timer) return;//�γ��˰���ͨ��
		now2.push_back(k);
	}
	ground[x][y]=ground[x][y+C]=true;
	ans++;
	int id;
	id=grand(hash(x,y));
	for(int i=0;i<now1.size();i++)
		merge(now1[i],id);
	id=grand(hash(x,y+C));
	for(int i=0;i<now2.size();i++)
		merge(now2[i],id);
}
int main(){
	//freopen("t1.in","r",stdin);
	scanf("%d%d%d",&R,&C,&N);
	memset(ufs,-1,sizeof(ufs));
	//for(int i=0;i<R;i++){for(int j=0;j<2*C;j++){printf("%3d ",hash(i,j));}cout<<endl;}
	int x,y;
	for(int i=1;i<=N;i++){
		scanf("%d%d",&x,&y);
		reclamate(x-1,y-1);
	}
	printf("%d\n",ans);
	return 0;
}
