#include<iostream>

using namespace std;

int main() {
	long int b1, b2, N, M, K, currentcolor=2;
	bool done=false;
	cin>>N>>M>>K;
	int Board[N][M];
	for (int i=0; i<K; i++) {
		cin>>b1;
		cin>>b2;
		Board[b1][b2]=1;
	}
	while (done==false) {
		//prvi boja koja nije crna
		for (int i=1; i<=N; i++) {
			for (int j=1; j<=M; j++) {
				if (Board[j][i]==0) {
					Board[j][i]=currentcolor;
					j=M;
					i=N;
				}
			}
		}
		//check okolo
		for (int i=1; i<=N; i++) {
			for (int j=1; j<=M; j++) {
				if (Board[j][i]=currentcolor) {
					if (Board[j+1][i]==0) {
						Board[j+1][i]=currentcolor;
					}
					if (Board[j][i+1]==0) {
						Board[j][i+1]=currentcolor;
					}
					if (Board[j-1][i]==0) {
						Board[j-1][i]=currentcolor;
					}
					if (Board[j][i-1]==0) {
						Board[j][i-1]=currentcolor;
					}				
				}
			}
		}
		//checking if its done
		done=true;
		for (int i=1; i<=N; i++) {
			for (int j=1; j<=M; j++) {
				if(Board[j][i]==0) {
					done=false;
					i=N;
					j=M;
					currentcolor++;
				}
			}
		}
	}
	cout<<currentcolor-1;
	return 0;
}