using System;

namespace Zadatak4Takmicenje3
{
    class Program
    {
        static void boji(ref int[,] matr, int i, int j, int boja, int n, int m)
        {
            if (i != 0 && matr[i - 1, j] == 0)
            {
                matr[i - 1, j] = boja;
                boji(ref matr, i - 1, j, boja, n, m);
            }
            else if (j != 0 && matr[i, j - 1] == 0)
            {
                matr[i, j - 1] = boja;
                boji(ref matr, i, j - 1, boja, n, m);
            }
            else if (i != n - 1 && matr[i + 1, j] == 0) 
            {
                matr[i + 1, j] = boja;
                boji(ref matr, i + 1, j, boja, n, m);
            }
            else if (j != m - 1 && matr[i, j + 1] == 0)
            {
                matr[i, j + 1] = boja;
                boji(ref matr, i, j + 1, boja, n, 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]);
            int[,] matr = new int[n, m];
            for (int i = 0; i < k; i++)
            {
                s = Console.ReadLine().Split();
                matr[int.Parse(s[0]) - 1, int.Parse(s[1]) - 1] = 1;
            }
            int boja = 2;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (matr[i, j] == 0)
                    {
                        if (j != 0 && matr[i, j - 1] != 0 && matr[i, j - 1] != 1)
                            matr[i, j] = boja;
                        else if (i != 0 && matr[i - 1, j] != 0 && matr[i - 1, j] != 1)
                            matr[i, j] = boja;
                        else if (i != n - 1 && matr[i + 1, j] != 0 && matr[i + 1, j] != 1)
                            matr[i, j] = boja;
                        else if (j != m - 1 && matr[i, j + 1] != 0 && matr[i, j + 1] != 1)
                            matr[i, j] = boja;
                        else 
                        {
                            matr[i, j] = boja;
                            boji(ref matr, i, j, boja, n, m);
                            boja++;
                        }
                    }
                }
            }
            Console.WriteLine(boja - 2);
        }
    }
}