using System;

namespace D_Boje
{
    class Program
    {
        static int Prebroji(bool[,] a, int n, int m)
        {
            int c = 0;
            
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (!a[i, j] && Boja(a, n, m, i, j))
                    {
                        c++;
                    }
                }
            }
            
            return c;
        }
        
        static bool Boja(bool[,] a, int n, int m, int i, int j)
        {
            if (Moguce(a, n, m, i, j) && !a[i, j])
            {
                a[i, j] = true;

                Boja(a, n, m, i + 1, j);
                Boja(a, n, m, i, j + 1);
                Boja(a, n, m, i - 1, j);
                Boja(a, n, m, i, j - 1);
                
                return true;
            }

            return false;
        }

        static bool Moguce(bool[,] a, int n, int m, int i, int j)
        {
            return i >= 0 && j >= 0 && i < n && j < m;
        }
        
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int k = int.Parse(s[2]);

            bool[,] a = new bool[n, m];

            for (int i = 0; i < k; i++)
            {
                s = Console.ReadLine().Split();
                a[int.Parse(s[0]) - 1, int.Parse(s[1]) - 1] = true;
            }
            
            Console.WriteLine(Prebroji(a, n, m));
        }
    }
}