#include<bits/stdc++.h>

using namespace std;

void dfs(long x,long y,long** o,long n,long m)
{
    o[x][y]=1;

    if (x-1>=0  && o[x-1][y]==0) {o[x-1][y]=1; dfs(x-1,y,o,n,m);  }
        if (x+1<n  && o[x+1][y]==0) { o[x+1][y]=1;dfs(x+1,y,o,n,m); }
        if (y-1>=0  && o[x][y-1]==0) {o[x][y-1]=1; dfs(x,y-1,o,n,m); }
        if (y+1<m  && o[x][y+1]==0) {o[x][y+1]=1; dfs(x,y+1,o,n,m); }
}

int main()
{
    long n,m,k;
    scanf("%d%d%d",&n,&m,&k);



    long** o=new long*[n];
    for (long i=0;i<n;i++)
    {
        o[i]=(long*)calloc(n,sizeof(long));
    }
    long x,y;
    for (long i=0;i<k;i++)
    {
        scanf("%ld%ld",&x,&y);
        x=x-1;
        y=y-1;
        o[x][y]=1;
    }

    long brojac=0;
    for (long i=0;i<n;i++)
    {
        for (long j=0;j<m;j++)
            if (o[i][j]==0)
            {
                x=i;
                y=j;
                dfs(x,y,o,n,m);
                brojac=brojac+1;
            }
    }
    printf("%ld",brojac);
    return 0;
}