/*#include <iostream>
#include <stdio.h>
#include <queue>*/
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,i,j,br=0,m,x,y,k;
    scanf("%d %d %d",&n,&m,&k);
    short int a[n][m];
    for (i=0;i<n;i++){
      for (j=0;j<m;j++){
        a[i][j]=0;
      }
    }
    for(i=0;i<k;i++)
    {
        scanf("%d %d",&x,&y);
        a[x-1][y-1]=1;
    }
    for (i=0;i<n;i++){
        for (j=0;j<m;j++){
            if (a[i][j]==0){
                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;
    }
  }
                br++;
      }
    }
  }
    printf("%d",br);
    return 0;
}