#include<bits/stdc++.h>

#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

int mark[2001][2001];
int n, m, k;

bool moze(int i, int j)
{
    return i >= 1 && i <= n && j >= 1 && j <= m && mark[i][j] == 0;
}

void dfs(int i, int j, int boja)
{
    mark[i][j] = boja;
    if(moze(i+1, j)) dfs(i+1, j, boja);
    if(moze(i-1, j)) dfs(i-1, j, boja);
    if(moze(i, j+1)) dfs(i, j+1, boja);
    if(moze(i, j-1)) dfs(i, j-1, boja);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    cin >> n >> m >> k;
    for(int i = 0; i < k; i++)
    {
        int a, b;
        cin >> a >> b;
        mark[a][b] = 1;
    }
    int boja = 2;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            if(mark[i][j] == 0)
                dfs(i, j, boja), boja++;
    cout << boja - 2;


    return 0;
}