#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, m, k, x, y, b = 2;
    scanf("%d %d %d", &m, &n, &k);
    int i, j = 0;
    int arr[m][n];
    for(i = 0; i < m; i++)
    {
        for(j = 0; j < n; j++) arr[i][j] = 0;
    }

    for(i = 0; i < k; i++)
    {
        scanf("%d %d", &x, &y);
        arr[x - 1][y - 1] = 1;
    }
    for(i = 0; i < m; i++)
    {
        for(j = 0; j < n; j++)
        {

            if(arr[i][j] == 0)
            {
                oboji(i, j, b, m, n, arr);
                b++;
            }
        }
    }
    printf("%d", b-2);
}

void oboji(int x, int y, int b, int m, int n, int arr[m][n])
{
    if(x >= 0 && x < m && y < n && y >= 0 && arr[x][y]==0)
    {
        arr[x][y] = b;
        oboji(x-1, y, b, m, n, arr);
        oboji(x, y-1, b, m, n, arr);
        oboji(x+1, y, b, m, n, arr);
        oboji(x, y+1, b, m, n, arr);
    }
}