#include <iostream>

using namespace std;

bool mat[1005][1005];
int n, m;

void traverse(int x, int y){
    if (x < 1 || x > n || y < 1 || y > m)
        return;
    mat[x][y] = true;
    if (mat[x+1][y] == false)
        traverse(x+1, y);
    if (mat[x][y+1] == false)
        traverse(x, y+1);
    if (mat[x-1][y] == false)
        traverse(x-1, y);
    if (mat[x][y-1] == false)
        traverse(x, y-1);
}

int main()
{
    int k;
    cin >> n >> m >> k;
    for (int i = 0; i < k; ++i){
        int x, y;
        cin >> x >> y;
        mat[x][y] = true;
    }
    int br = 0;
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= m; ++j){
            if (mat[i][j] == false){
                br++;
                traverse(i, j);
            }
        }
    }
    cout << br;
    return 0;
}