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

int mat[1005][1005];
bool visited[1005][1005];

int n, m;

void dfs(int x, int y){
    if(x < 0 || x >= n || y < 0 || y >= m || visited[x][y] || mat[x][y])
        return;
    visited[x][y] = true;
    dfs(x - 1, y);
    dfs(x + 1, y);
    dfs(x, y + 1);
    dfs(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 - 1][y - 1] = 1;
    }
    int res = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(!visited[i][j] && !mat[i][j]){
                dfs(i, j);
                res++;
            }
        }
    }

    cout << res << "\n";
    return 0;
}