#include<iostream>
#include<vector>


using namespace std;



void DFS(vector<vector<char>>Tabla, int i, int j,int n,int m) {

	if (i < 0 || j < 0 || i >= n || j >= m || Tabla[i][j] != '1') return;
	Tabla[i][j] = '0';
	DFS(Tabla, i + 1, j,n,m);
	DFS(Tabla, i - 1, j,n,m);
	DFS(Tabla, i, j + 1,n,m);
	DFS(Tabla, i, j - 1,n,m);

}
int main() {
	int n,m,k;
	cin >> n >> m >> k;
	vector<vector<char>>Tabla(n,vector<char>(m,'1'));

	for (int i = 0; i < k; i++) {
		int x, y;
		cin >> x >> y;
		Tabla[x - 1][y - 1] = '0';
	}

	int count = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			if (Tabla[i][j] == '1') {
				DFS(Tabla, i, j, n, m);
				++count;
			}
	}

	cout<<count;

	return 0;
}