#include <iostream>
using namespace std;

void fill(int** mat, int x, int y, int c, int n, int m) {
	mat[x][y] = c;
	if (mat[x + 1][y] == 0) {
		mat[x + 1][y] = c; fill(mat, x + 1, y, c, n, m);
	}
	if (mat[x - 1][y] == 0) {
		mat[x - 1][y] = c; fill(mat, x - 1, y, c, n, m);
	}
	if (mat[x][y + 1] == 0) {
		mat[x][y + 1] = c; fill(mat, x, y + 1, c, n, m);
	}
	if (mat[x][y - 1] == 0) {
		mat[x][y - 1] = c; fill(mat, x, y - 1, c, n, m);
	}
	else return;
}

int main() {
	int n, m, k, ** mat;
	cin >> n >> m >> k; n += 2; m += 2; mat = new int* [n];
	for (int i = 0; i < n; i++) {
		mat[i] = new int[m];
	}
	int c = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (i == 0 || i == n - 1 || j == 0 || j == m - 1) { mat[i][j] = -1; }
			else { mat[i][j] = 0; }
		}
	}
	for (int i = 0; i < k; i++) {
		int x, y;
		cin >> x >> y;
		mat[x][y] = -1;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (mat[i][j] == 0) {
				c++;
				fill(mat, i, j, c, n, m);
			}
		}
	}
	cout << c;
	return 0;
}