#include <iostream>
#include <stdio.h>
#include <queue>


using namespace std;
int a[1000][1000];


void obidji(int a[1000][1000],int i,int j,int n,int m){
  queue <int>qx;
  queue <int>qy;
  qx.push(i);
  qy.push(j);
  a[i][j]=2;
  while(!qx.empty()){
    i=qx.front();
    j=qy.front();
    qx.pop();
    qy.pop();
    if(i>0 && a[i-1][j]==0){
      qx.push(i-1);
      qy.push(j);
      a[i-1][j]=2;
    }
    if(j>0 && a[i][j-1]==0){
      qx.push(i);
      qy.push(j-1);
      a[i][j-1]=2;
    }
    if(i<n-1 && a[i+1][j]==0){
      qx.push(i+1);
      qy.push(j);
      a[i+1][j]=2;
    }
    if(j<m-1 && a[i][j+1]==0){
      qx.push(i);
      qy.push(j+1);
      a[i][j+1]=2;
    }
  }

}

int brojSoba(int a[1000][1000], int n, int m){
  int i, j, br = 0;
  for (i=0;i<n;i++){
    for (j=0;j<m;j++){
      if (a[i][j]==0){
        obidji(a,i,j,n,m);
        br++;

      }
    }
  }
return br;
}

int main(){
    int n,i,j,br=0,m,k,l;
    scanf("%i",&n);
    scanf("%i",&m);
    scanf("%d",&k);
    for(l=0;l<k;l++)
    {

        scanf("%d",&i);
        scanf("%d",&j);
        i--;
        j--;
        a[i][j]=1;
    }

    br = brojSoba(a, n, m);
    printf("%d",br);
    return 0;
}