#include <stdio.h>
#include <stdlib.h>
#define INDEX(X, Y, N) (Y) * (N) + (X)

int boja = 1;

void oboji(int *platno, int x, int y, int n, int m) {
    if(platno[INDEX(x, y, n)] == 0) {
        platno[INDEX(x, y, n)] = boja;
        if (x-1 >= 0) oboji(platno, x-1, y, n, m);
        if (x+1 < n ) oboji(platno, x+1, y, n, m);
        if (y-1 >= 0) oboji(platno, x, y-1, n, m);
        if (y+1 < m ) oboji(platno, x, y+1, n, m);
    }
}

int main() {
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);
    int *platno = (int *) calloc(n * m, sizeof(int));
    int x1, x2;

    for (int i = 0; i < k; ++i) {
        scanf("%d %d", &x1, &x2);
        --x1;
        --x2;
        platno[INDEX(x1, x2, n)] = -1;
    }

    for (int j = 0; j < n; ++j) {
        for (int i = 0; i < m; ++i) {
            if(platno[INDEX(j, i, n)] == 0) {
                oboji(platno, j, i, n, m);
                ++boja;
            }
        }
    }

    printf("%d", --boja);
    return 0;
}