#include<iostream>
#include <stack> 
using namespace std;

bool A[1001][1001];

struct Tacka
{
	int x, y;
};

void poplava(int x, int y,int N,int M)
{
	Tacka temp;
	

	stack<Tacka> stack;
	temp.x = x;
	temp.y = y;
	stack.push(temp);
	while (stack.size() > 0)
	{
		Tacka p = stack.top();
		stack.pop();

		A[p.y][p.x] = true;
		if (p.x > 0 && !A[p.y][p.x-1])
		{
			temp.x = p.x - 1; temp.y = p.y;
			stack.push(temp);
		}
		if (p.x < N-1 && !A[p.y][p.x + 1])
		{
			temp.x = p.x + 1; temp.y = p.y;
			stack.push(temp);
		}
		if (p.y > 0 && !A[p.y - 1][p.x])
		{
			temp.x = p.x; temp.y = p.y-1;
			stack.push(temp);
		}
		if (p.y < M-1 && !A[p.y + 1][p.x])
		{
			temp.x = p.x; temp.y = p.y+1;
			stack.push(temp);
		}	
	}
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int N, M,K;

	cin >> N >> M >> K;
	int xi, yi;

	for (int i = 0; i < M; i++)
	{
		for (int j = 0; j < N; j++)
		{
			A[i][j] = false;
		}
	}

	for (int i = 0; i < K; i++)
	{
		cin >> xi >> yi;
		A[yi-1][xi-1] = true;
	}

	int brojac = 0;

	for (int i = 0; i < M; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (!A[i][j])
			{
				poplava(j, i, N, M);
				brojac++;
			}
		}
	}

	cout << brojac;
	return 0;
}