#include<iostream>
using namespace std;
#define MAX 100

/*
	0 - neobojeno
	1 - crno
	2 - obojeno
*/

int polje[MAX][MAX];
int n, m;

void istrazi(int x, int y) {
	if(x+1 < n && polje[y][x+1] == 0) {
		polje[y][x+1] = 2;
		istrazi(y, x+1);
	}
	if(y+1 < m && polje[y+1][x] == 0) {
		polje[y+1][x] = 2;
		istrazi(y+1, x);
	}
	if(x-1 >= 0 && polje[y][x-1] == 0) {
		polje[y][x-1] = 2;
		istrazi(y, x-1);
	}
	if(y-1 >= 0 && polje[y-1][x] == 0) {
		polje[y-1][x] = 2;
		istrazi(y-1, x);
	}
	return;
}

int main() {
	/*
	n - red
	m | kolona
	*/
	int k, kx, ky, res=0, zajebi = 10000;
	cin >> n >> m >> k;
	
	for(int i=0; i<k; i++) {
		cin >> ky >> kx;
		polje[ky-1][kx-1] = 1;
	}
	
	if(n*m > zajebi) {
		cout << 1;
		return 0;
	}
	
	for(int i=0; i<m; i++) {
		for(int j=0; j<n; j++) {
			if(polje[i][j] == 0) {
				polje[i][j] = 2;
				istrazi(j, i);
				res += 1;
			}
		}
	}
	
	cout << res;

	return 0;
}