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

namespace kval33
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            var data = line.Split(' ');
            long n = Convert.ToInt64(data[0]);
            long m = Convert.ToInt64(data[1]);
            long k = Convert.ToInt64(data[2]);

            int[,] a = new int[n + 2, m + 2];
            
            for (long i = 0; i <= n + 1; i++)
                for (long j = 0; j <= m + 1; j++)
                {
                    if (j == 0 || j == m + 1 || i == 0 || i == n + 1)
                        a[i, j] = -1;
                    else
                        a[i, j] = 0;
                }
            for (long i = 1; i <= k; i++)
            {
                line = Console.ReadLine();
                data = line.Split(' ');
                a[Convert.ToInt32(data[0]), Convert.ToInt32(data[1])] = -1;
            }
            int boja = 0;
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= m; j++)
                {
                    if (a[i, j] != -1)
                    {
                        if (a[i - 1, j] < 0 && a[i, j - 1] < 0)
                        {
                            boja++;
                            a[i, j] = boja;
                        }
                        
                        if (a[i, j] > 0 && a[i, j + 1] > 0 && a[i, j] > a[i, j + 1])
                        {
                            boja--;
                            a[i, j]--;
                        }
                        if (a[i + 1, j] == 0)
                            a[i + 1, j] = boja;
                        if (a[i, j + 1] == 0)
                            a[i, j + 1] = boja;
                    }
                }
            }
            Console.WriteLine(boja);
        }
    }
}