using System;

namespace petljazad4
{
    class Program
    {
        static int[,] metoda1(int i, int j, int[,] a, int n, int m)
        {
            a[i, j] = 1;
            if (i - 1 >= 0)
            {
                if (a[i - 1, j] == 0)
                {
                    a = metoda1(i - 1, j,a, n, m);
                }
            }
            if (j - 1 >= 0)
            {
                if (a[i, j - 1] == 0)
                {
                    a = metoda1(i, j - 1,  a, n, m);
                }
            }
            if (i + 1 < n)
            {
                if (a[i + 1, j] == 0)
                {
                    a = metoda1(i + 1, j,  a, n, m);
                }
            }
            if (j + 1 < m)
            {
                if (a[i, j + 1] == 0)
                {
                    a = metoda1(i, j + 1,  a, n, m);
                }
            }

            return a;
        }


        static void Main(string[] args)
        {
            int br = 0;
            string input1 = Console.ReadLine();
            int n = Convert.ToInt32(input1.Substring(0, input1.IndexOf(" ")));
            input1 = input1.Substring(input1.IndexOf(" ") + 1);
            int m = Convert.ToInt32(input1.Substring(0, input1.IndexOf(" ")));
            input1 = input1.Substring(input1.IndexOf(" ") + 1);
            int[,] a = new int[n,m];
            int k = Convert.ToInt32(input1);
            for (int i = 0; i < k; i++)
            {
                input1 = Console.ReadLine();
                int x = Convert.ToInt32(input1.Substring(0, input1.IndexOf(" "))) - 1;
                int y = Convert.ToInt32(input1.Substring(input1.IndexOf(" ") + 1)) - 1;
                a[x, y] = 1;
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if((a[i,j] == 0))
                    {
                        br++;
                        a = metoda1(i, j, a, n, m);
                    }
                    
                }
                
            }
            Console.WriteLine(br);
        }
    }
}