using System;
using System.Linq;

namespace petlja
{
	class Program
	{
		static void Flood(int x, int y, int boja, int width, int height, int[,] mat)
		{
			if (x < 0 || x >= width) return;
			if (y < 0 || y >= height) return;
			if(mat[x,y] == 0)
			{
				mat[x, y] = boja;
				Flood(x+1, y, boja, width, height, mat);
				Flood(x, y+1, boja, width, height, mat);
				Flood(x-1, y, boja, width, height, mat);
				Flood(x, y-1, boja, width, height, mat);
			}
		}

		static void Main(string[] args)
		{
			string[] unos = Console.ReadLine().Split();
			int n = int.Parse(unos[0]);
			int m = int.Parse(unos[1]);
			int k = int.Parse(unos[2]);

			int[,] tabla = new int[n, m];
			for (int i = 0; i < k; i++)
			{
				unos = Console.ReadLine().Split();
				int x = int.Parse(unos[0]) - 1;
				int y = int.Parse(unos[1]) - 1;

				tabla[x, y] = -1;
			}


			int boja = 0;
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < m; j++)
				{
					if (tabla[i, j] != 0)
						continue;
					boja++;
					Flood(i, j, boja, n, m, tabla);					
				}
			}
			
			Console.WriteLine(boja);

		}
	}
}