#include<iostream>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;
const int N = 1005;
int mt[N][N];
int i, j, x, y, n, m, k, p, r;
const int d1[] = { 1,0,0,-1 };
const int d2[] = { 0,1,-1,0 };
void dfs(int x,int y) {
	int nx, ny;
	mt[x][y] = 1;
	for (i = 0; i < 4; ++i) {
		nx = x + d1[i], ny = y + d2[i];
		if (!mt[nx][ny])dfs(nx, ny);
	}
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m >> k;
	for (i = 0; i <= 1000; ++i) {
		mt[i][0] = mt[0][i] = mt[n+1][i] = mt[i][m + 1] = 1;
	}
	while (k--) {
		cin >> x >> y;
		mt[x][y] = 1;
	}
	for (i = 1; i <= n; ++i) {
		for (j = 1; j <= m; ++j) {
			if (!mt[i][j]) {
				++r;
				dfs(i, j);
			}
		}
	}
	cout << r << '\n';
}