#include <iostream>
using namespace std;


void resiSusede(int x, int y, int boja, int n, int m, int** mat)
{
	mat[x][y] = boja;
	int sused1 = -1, sused2 = -1, sused3 = -1, sused4 = -1;

	if (x - 1 >= 1)
		sused1 = mat[x - 1][y];
	if (x + 1 <= n)
		sused2 = mat[x + 1][y];
	if (y - 1 >= 1)
		sused3 = mat[x][y - 1];
	if (y + 1 <= m)
		sused4 = mat[x][y + 1];

	if (sused1 == 0)
		resiSusede(x - 1, y, boja, n, m, mat);
	if (sused2 == 0)
		resiSusede(x + 1, y, boja, n, m, mat);
	if (sused3 == 0)
		resiSusede(x, y - 1, boja, n, m, mat);
	if (sused4 == 0)
		resiSusede(x, y + 1, boja, n, m, mat);
}

int main()
{
	int n, m, k;
	int a, b;
	int novaBoja = 2;
	int brojacBoja = 0;
	cin >> n >> m;
	cin >> k;
	int** mat = new int* [n];
	for (int i = 1; i <= n; i++)
		mat[i] = new int[m];

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			mat[i][j] = 0;
		}
	}
	for (int i = 1; i <= k; i++)
	{
		cin >> a >> b;
		mat[a][b] = 1;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			if (mat[i][j] == 0)
			{
				int x = i;
				int y = j;
				resiSusede(x, y, novaBoja, n, m, mat);
				novaBoja++;
				brojacBoja++;
			}
		}
	}
	cout << brojacBoja;
	return 0;
}