#include <bits/stdc++.h>
using namespace std;
bool mat[10007][10007];

void flood(int i, int j)
{
    if (mat[i][j])
        return;
    mat[i][j] = true;
    flood(i-1, j);
    flood(i+1, j);
    flood(i, j-1);
    flood(i, j+1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    int result = 0;
    for (int i = 0; i <= n+1; i++)
    {
        mat[i][0] = true;
        mat[i][m+1] = true;
    }
    for (int i = 0; i <= m+1; i++)
    {
        mat[n+1][i] = true;
        mat[0][i] = true;
    }
    int u, v;
    while (k--) {
        cin >> u >> v;
        mat[u][v] = true;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (mat[i][j] == false)
            {
                result += 1;
                flood(i, j);
            }
        }
    }
    cout << result;
    return 0;
}