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

namespace Cetvrti_Zadatak
{
    class Program
    {
        static void Promeni(short[,] matrica,short IzBroja,short UBroj,int kolona,int M)
        {
            bool x = false;
            for (int i = 1; i < M; i++)
            {
                if (matrica[kolona, i] == IzBroja)matrica[kolona, i] = UBroj;
            }
            return;
        }
        static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = Convert.ToInt32(s[0]), M = Convert.ToInt32(s[1]), K = Convert.ToInt32(s[2]);
            short[,] matrica = new short[N + 1, M + 1];
            short boja = 0;
            for (int i = 0; i < M + 1; i++) matrica[0, i] = -1;
            for (int i = 0; i < N + 1; i++) matrica[i, 0] = -1;
            for (int i = 0; i < K; i++) {
                s = Console.ReadLine().Split(' ');
                matrica[Convert.ToInt32(s[0]), Convert.ToInt32(s[1])] = -1;
            }
            for (int i = 1; i < N + 1; i++) for (int j = 1; j < M + 1; j++)
                {
                    if (matrica[i, j] != 0) continue;
                    if (matrica[i, j - 1] == -1)
                    {
                        boja++;
                        matrica[i, j] = boja;
                    }
                    else matrica[i, j] = matrica[i, j - 1];
                }
            for (int i = 1; i < N + 1; i++) for (int j = 1; j < M + 1; j++)
                {
                    if (matrica[i - 1, j] != -1 && matrica[i, j] != -1  && matrica[i - 1, j] != matrica[i, j])
                    {
                        Promeni(matrica, matrica[i - 1, j], matrica[i, j], i - 1, M + 1);
                        boja--;
                    }
                }
            Console.WriteLine(boja);
        }
    }
}