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

void popuna( int n, int m, int tbl[n][m], int i, int j, int nb, int d )
{
    if ( i > 0 && d != 1 )
        if ( tbl[i-1][j] == 0 )
        {
            tbl[i-1][j] = nb+1;
            popuna( n, m, tbl, i-1, j, nb, 2 );
        }
     if ( i < n - 1 && d != 2 )
        if ( tbl[i+1][j] == 0 )
        {
            tbl[i+1][j] = nb+1;
            popuna( n, m, tbl, i+1, j, nb, 1 ); 
        }
    if ( j > 0 && d != 3 )
        if ( tbl[i][j-1] == 0 )
        {
            tbl[i][j-1] = nb+1;
            popuna( n, m, tbl, i, j-1, nb, 4 );
        }
    if ( j < m - 1 && d != 4 )
        if ( tbl[i][j+1] == 0 )
        {
            tbl[i][j+1] = nb+1;
            popuna( n, m, tbl, i, j+1, nb, 3 );
        }
}

int main()
{
    static int n, m, k;
    int nb = 0;

    scanf("%d %d %d", &n, &m, &k );

    int tbl[n][m];

    for( int i = 0; i < n; i++ )
        for( int j = 0; j < m; j++ )
            tbl[i][j] = 0;

    for( int i = 0; i < k; i++ )
    {
        int ai, bi;
        scanf("%d %d", &ai, &bi );
        tbl[ai-1][bi-1] = -1;
    }

    for( int i = 0; i < n; i++ )
    {
        for( int j = 0; j < m; j++ )
        {
            if ( tbl[i][j] == 0 )
            {

                tbl[i][j] = nb+1;

                popuna( n, m, tbl, i, j, nb, 0 );
                nb++;
            }
        }
    }

    printf("%d", nb );

    return 0;
}