using System;
using System.Collections.Generic;

namespace Zadatak4Takmicenje3_2._0
{
    class Program
    {
        static void Boji(ref int [,] matrica,int x, int y, int boja, int crna,int maxx,int maxy)
        {
            if (matrica[x, y] != boja && matrica[x, y] != crna)
            {
                matrica[x, y] = boja;
                if (x + 1 != maxx) 
                Boji(ref matrica, x + 1, y, boja, 1, maxx, maxy);
                if (y + 1 != maxy) 
                Boji(ref matrica, x, y + 1, boja, 1, maxx, maxy);
                if (x - 1 != -1) 
                Boji(ref matrica, x - 1, y, boja, 1, maxx, maxy);
                if (y - 1 != -1)
                Boji(ref matrica, x, y - 1, boja, 1, maxx, maxy);
            }
        }
        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)
                    {
                        Boji(ref matr, i, j, boja, 1, n, m);
                        boja++;
                    }
                }
            }
            Console.WriteLine(boja - 2);
        }
    }
}