#include <iostream>

using namespace std;

bool proveri(long long mat[1000][1000], long long i, long long j,long long n,long long m)
{
  if(mat[i][j] == 1) return false;
  if(i == 0) return false;
  if(j == 0) return false;
  if(i > n) return false;
  if(j > m) return false;
  return true;
}

void fun(long long mat[1000][1000], long long i , long long j, long long n ,long long m)
{
  if(proveri(mat,i,j,n,m))
  {
    mat[i][j] = 1;
    fun(mat, i+1, j, n, m);
    fun(mat, i-1, j, n, m);
    fun(mat, i, j+1, n ,m);
    fun(mat, i, j-1, n, m);
  }
  
}

int main(){
  long long brojac = 0;

  long long mat[1000][1000] = {};
  
  long long n ,m , k;
  cin >> n >> m >> k;

  for(long long i = 0 ; i < k ; i++)
    {
      long long crnoPoljex , crnoPoljey;
      cin >> crnoPoljex >> crnoPoljey;
      mat[crnoPoljex][crnoPoljey] = 1;
    }
  
  for(long long i = 1 ; i < n + 1 ; i ++)
  {
    for(long long j = 1 ; j < m + 1 ; j++)
      if(mat[i][j] == 0){ 
        fun(mat, i, j, n, m);
        brojac ++;
      }
  }
  
  cout << brojac;

}