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

namespace ConsoleApp19
{
    class Program
    {
        static void Main(string[] args)
        {
              string str = Console.ReadLine();
              string[] s = str.Split(' ');
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int k = int.Parse(s[2 ]);
            int[,] mat = new int[n+2, m+2];
            int[] niz = new int[k+1];
            int[] niz1 = new int[k+1];

            
            for (int i = 1; i <=k; i++)
            {
                string str1 = Console.ReadLine();
                string[] s1 = str1.Split(' ');
                niz[i] = int.Parse(s1[0]);
                niz1[i] = int.Parse(s1[1]);
                mat[niz[i], niz1[i]] = -1;
            }
            for (int i = 0; i < n+2; i++)
            {
                mat[i, 0] = -1;
                mat[i, m + 1] = -1;
            }
            for (int i = 0; i < m+2; i++)
            {
                mat[0, i] = -1;
                mat[n + 1, i] = -1;
            }
            int b = 1;
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= m; j++)
                {
                    if (mat[i, j] != -1)
                    {
                        mat[i, j] = b;
                        b++;
                    }
                    
                }
                
            }
           
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= m; j++)
                {
                    if (mat[i, j] != -1)
                    {
                        if (mat[i + 1, j] != -1)  mat[i + 1, j] = mat[i, j]; 
                        if (mat[i, j + 1] != -1)  mat[i, j + 1] = mat[i, j]; 
                        if (mat[i - 1, j] != -1)  mat[i - 1, j] = mat[i, j];
                        if (mat[i, j - 1] != -1)  mat[i, j - 1] = mat[i, j]; 
                        
                    }

                }

            }
            int[] niz2 = new int[(n + 2) * (m + 2)+1];
            int w = 0;
            for (int i = 0; i <= n+1; i++)
            {
                for (int j = 0; j <= m+1; j++)
                {
                    
                    niz2[w] = mat[i, j];
                    
                    
                    w++;
                 
                }
                
            }
            
            Array.Sort(niz2);
            int l = -1;
            for (int i = 1; i < w; i++)
            {
                if (niz2[i-1] != niz2[i ]) l++; 
               
            }
            Console.WriteLine(l);
        }
    }
}