#include <iostream>
using namespace std;
void oboji(int **a, int n, int m, int i, int j, int boja)
{
	if (i >= 0 && j >= 0 && i < n && j < m && a[i][j] != 1 && a[i][j] == 0)
	{
		a[i][j] = boja;
		oboji(a, n, m, i - 1, j, boja);
		oboji(a, n, m, i, j + 1, boja);
		oboji(a, n, m, i + 1, j, boja);
		oboji(a, n, m, i, j - 1, boja);
	}
}
int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	int **a = (int**)malloc(n * sizeof(int*));
	for (int i = 0; i < n; i++)
	{
		a[i] = (int*)malloc(m * sizeof(int));
	}
	for (int i = 0; i < k; i++)
	{
		int x, y;
		cin >> x >> y;
		a[x - 1][y - 1] = 1;
	}
	int boja = 2, br = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (a[i][j] == 0)
			{
				br++;
				boja++;
				oboji(a, n, m, i, j, boja);
			}
		}
	}
	cout << br << endl;

	return 0;
}