//Failure will never overtake me if my determination to succeed is strong enough
#include <bits/stdc++.h>

using namespace std;

void dfs(int a[][1000], int n, int m, int i, int j)
{
    a[i][j] = 1;

    if(i-1 >= 0 && a[i-1][j] == -1)
        dfs(a, n, m, i-1, j);
    if(j+1 < m && a[i][j+1] == -1)
        dfs(a, n, m, i, j+1);
    if(i+1 < n && a[i+1][j] == -1)
        dfs(a, n, m, i+1, j);
    if(j-1 >= 0 && a[i][j-1] == -1)
        dfs(a, n, m, i, j-1);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, k;
    cin >> n >> m >> k;
    int a[n][1000];

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            a[i][j] = -1;
        }
    }

    for(int i = 0; i < k; i++)
    {
        int x, y;
        cin >> x >> y;
        a[x-1][y-1] = 0;
    }


    int komp = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(a[i][j] == -1)
            {
                dfs(a, n, m, i, j);
                komp++;

            }
        }
    }

    cout << komp;

}