#include<iostream>
#include<stdio.h>
#define MAX 1000000005

using namespace std;

int k[MAX][MAX];

void boji(int x, int y, int n, int m)
{
	k[x][y]++;
	if(x > 1 && !k[x - 1][y])	boji(x - 1, y, n, m);
	if(x < n && !k[x + 1][y])	boji(x + 1, y, n, m);
	if(y > 1 && !k[x][y - 1])	boji(x, y - 1, n, m);
	if(y < m && !k[x][y + 1])	boji(x, y + 1, n, m);
}

int main()
{
	int n, m, c, x, y, br = 0;
	cin >> n >> m >> c;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <=m;j++)
			k[i][j] = 0;
	for(int i = 0;i < c;i++)
	{
		cin >> x >> y;
		k[x][y]++;
	}
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)
			if(!k[i][j])
			{
				br++;
				boji(i, j, n, m);
			}
	cout << br;
}