#include<iostream>
using namespace std;

int tabela[1000000000][1000000000];
int n, m;

void oboji(int i, int j){
    if(i != 0 && tabela[i - 1][j] == 0){
        tabela[i - 1][j] = tabela[i][j];
        oboji(i - 1, j);
    }
    if(i != n - 1 && tabela[i + 1][j] == 0){
        tabela[i + 1][j] = tabela[i][j];
        oboji(i + 1, j);
    }
    if(j != 0 && tabela[i][j - 1] == 0){
        tabela[i][j - 1] = tabela[i][j];
        oboji(i, j - 1);
    }
    if(j != n - 1 && tabela[i][j + 1] == 0){
        tabela[i][j + 1] = tabela[i][j];
        oboji(i, j + 1);
    }
}

int main(){
    int k, boje = 0, tren = 2;
    cin >> n >> m >> k;
    int x, y;
    for(int i = 0; i < k; i++){
        cin >> x >> y;
        tabela[x - 1][y - 1] = 1;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(tabela[i][j] == 0){
				tabela[i][j] = tren;
				oboji(i, j);
                tren++;
                boje++;
            }
        }
    }
    cout << boje;
    return 0;
}