#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 10000

int matrica[N][N];
ll brc=0;
ll n,m,k;

void popuni(ll i, ll j)
{
    matrica[i][j]=1;
    if(matrica[i+1][j]==0 && i<=n-1)
        popuni(i+1,j);
    if(matrica[i][j+1]==0 && j<=m-1)
        popuni(i,j+1);
    if(matrica[i-1][j]==0 && i>1)
        popuni(i-1,j);
    if(matrica[i][j-1]==0 && j>1)
        popuni(i,j-1);

}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin>>n>>m>>k;
    //cout<<"stizem";
    while(k--)
    {
        ll x,y;
        cin>>x>>y;
        matrica[x][y]=1;
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
            if(matrica[i][j]==0)
                popuni(i,j), brc++;
    }
    cout<<brc;
}