#include <iostream>

using namespace std;

int br = 0;
int boja = 1;

void fun(int i, int j, int** tabla, int N, int M){
    tabla[i][j] = boja;
    if (i != N-1 && tabla[i+1][j] == 0)
        fun(i+1, j, tabla, N, M);
    if (i != 0 && tabla[i-1][j] == 0)
        fun(i-1, j, tabla, N, M);
    if (j != M-1 && tabla[i][j+1] == 0)
        fun(i, j+1, tabla, N, M);
    if (j != 0 && tabla[i][j-1] == 0)
        fun(i, j-1, tabla, N, M);
}

int main()
{
    int N, M, K;
    cin >> N >> M >> K;

    int** tabla = new int*[N];
    for (int i = 0; i < N; i++) {
        tabla[i] = new int[M];
        for (int j = 0; j < M; j++)
            tabla[i][j] = 0;
    }

    int xi, yi;
    for (int i = 0; i < K; ++i){
        cin >> xi >> yi;
        tabla[xi-1][yi-1] = -1;
    }

    for (int i = 0; i < N; ++i){
        for (int j = 0; j < M; ++j){
            if (tabla[i][j] == 0){
                fun(i, j, tabla, N, M);
                ++boja;
                ++br;
            }
        }
    }

    cout << br;

    for (int i = 0; i < N; i++)
        delete[] tabla[i];
    delete[] tabla;

    return 0;
}