#include <iostream>

using namespace std;

bool proveri(int mat[1000][1000], int i, int j,int n, int 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(int mat[1000][1000], int i , int j, int n , int 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(){
  int brojac = 0;

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

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

}