using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			Stack<int[]> st = new Stack<int[]>();
			string[] s = Console.ReadLine().Split();
			int n = int.Parse(s[0]), m = int.Parse(s[1]), d = int.Parse(s[2]);
			int[,] tabla = new int[n, m];
			for (int i = 0; i < d; i++)
			{
				s = Console.ReadLine().Split();
				tabla[int.Parse(s[0]) - 1, int.Parse(s[1]) - 1] = -1;
			}
			int[] polje = new int[2];
			int br = 0, r, k;
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < m; j++)
				{
					if(tabla[i,j] == 0)
					{
						polje[0] = i; polje[1] = j; st.Push(polje);
						
						while(st.Count>0)
						{
							polje = st.Pop(); r = polje[0]; k = polje[1];
							if (r > 0 && tabla[r - 1, k] == 0)
							{
								tabla[r - 1, k] = 1; polje[0] = r - 1; polje[1] = k; st.Push(polje);
							}
							if (r < n - 1 && tabla[r + 1, k] == 0)
							{
								tabla[r + 1, k] = 1; polje[0] = r + 1; polje[1] = k; st.Push(polje);
							}
							if (k > 0 && tabla[r, k - 1] == 0)
							{
								tabla[r, k - 1] = 1; polje[0] = r; polje[1] = k - 1; st.Push(polje);
							}
							if (k < m - 1 && tabla[r, k + 1] == 0)
							{
								tabla[r, k + 1] = 1; polje[0] = r; polje[1] = k + 1; st.Push(polje);
							}
						}
						br++;
					}
				}
			}
			Console.WriteLine(br);
		}
	}
}