#include <iostream>
using namespace std;

int matrica[1000][1000];
int n, m;

void oboj(int i, int j, int br)
{
	if (i >= 1 && j >= 1 && i <= n && j <= m && matrica[i][j] == 0)
	{
		matrica[i][j] = br;
		oboj(i + 1, j, br);
		oboj(i - 1, j, br);
		oboj(i, j + 1, br);
		oboj(i, j - 1, br);
	}
}

int main()
{
	int k;
	cin >> n >> m >> k;
	for (int i = 0; i < k; i++)
	{
		int x, y;
		cin >> x >> y;
		matrica[x][y] = -1;
	}

	int br = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			if (matrica[i][j] == 0)
			{
				br++;
				oboj(i, j, br);
			}
		}
	}
	cout << br << "\n";

	return 0;
}