#include<iostream>
using namespace std;

int n, m;

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

int main(){
    int k, boje = 0, tren = 2;
    cin >> n >> m >> k;
    int x, y;
    int tabela[n][m];
    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, tabela[n][m]);
                tren++;
                boje++;
            }
        }
    }
    cout << boje;
    return 0;
}