#include <stdio.h>
#include <vector>

using namespace std;

vector <long long> a[1000000];

void DFS(long long i,long long j)
{
    a[i][j]=1;
    if (a[i+1][j]==0) DFS(i+1,j);
    if (a[i-1][j]==0) DFS(i-1,j);
    if (a[i][j+1]==0) DFS(i,j+1);
    if (a[i][j-1]==0) DFS(i,j-1);
}

int main()
{
    long long n,m,k;
    scanf("%lld%lld%lld",&n,&m,&k);
    for (long long i=0;i<n+10;i++)
        for (long long j=0;j<m+10;j++) a[i].push_back(0);
    for (long long i=0;i<n+2;i++)
    {
        a[i][0]=-1;
        a[0][i]=-1;
        a[i][m]=-1;
        a[n][i]=-1;
    }
    for (long long i=0;i<m+2;i++)
    {
        a[i][0]=-1;
        a[0][i]=-1;
        a[i][m+1]=-1;
        a[n+1][i]=-1;
    }
    for (long long i=0;i<k;i++)
    {
        long long x,y;
        scanf("%lld%lld",&x,&y);
        a[x][y]=1;
    }

    long long br=0;
    for (long long i=1;i<=n;i++)
        for (long long j=1;j<=m;j++)
        {
            if (a[i][j]==0)
            {
                br++;
                DFS(i,j);
            }
        }
    printf("%lld",br);
}