#include <bits/stdc++.h>
using namespace std;

unsigned short boja = 0;

void rekurzija(unsigned int x, unsigned int y, unsigned int n, unsigned int m, char **a){
    a[x][y] = 2;
    if(x < n && a[x + 1][y] == 0){
        rekurzija(x + 1, y, n, m, a);
    }
    if(x > 0 && a[x - 1][y] == 0){
        rekurzija(x - 1, y, n, m, a);
    }
    if(y > 0 && a[x][y - 1] == 0){
        rekurzija(x, y - 1, n, m, a);
    }
    if(y < m && a[x][y + 1] == 0){
        rekurzija(x, y + 1, n, m, a);
    }
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    unsigned int n, m, k, i, j, x, y;
    cin >> n >> m >> k;
    char **a = (char **)malloc(n);
    for(i = 0; i < n; i++){
        a[i] = (char *)malloc(m);
        for(j = 0; j < m; j++){
            a[i][j] = 0;
        }
    }
    for(i = 0; i < k; i++){
        cin >> x >> y;
        a[x-1][y-1] = 1;
    }
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            if(a[i][j] == 0){
                rekurzija(i, j, n - 1, m - 1, a);
                boja++;
            }
        }
    }
    cout << boja;
    return 0;
}