#include <iostream>
#include <queue>

using namespace std;

int bfs(bool d[][1002], int ka, int kb)
{
    queue <int> qa;
    queue <int> qb;
    qa.push(ka);
    qb.push(kb);
    int ca;
    int cb;
    int la[4] = {-1, 0, 1, 0};
    int lb[4] = {0, -1, 0, 1};
    while (!qa.empty())
    {
        ca = qa.front();
        qa.pop();
        cb = qb.front();
        qb.pop();
        for (int i = 0; i < 4; i++)
        {
            if (ca + la[i] >= 0 && cb + lb[i] >= 0)
            {
                if (d[ca + la[i]][cb + lb[i]] == 0)
                {
                    qa.push(ca + la[i]);
                    qb.push(cb + lb[i]);
                }
            }
        }
        d[ca][cb] = 1;
    }
    return 1;
}

int main()
{
    int n, m, k;
    int z = 0;
    cin >> n >> m >> k;
    bool d[n + 2][1002];
    for (int i = 0; i < n + 2; i++)
    {
        for (int j = 0; j < m + 2; j++)
        {
            if (i == 0 || i == n + 1 || j == 0 || j == m + 1)
            {
                d[i][j] = 1;
            }
            else
            {
                d[i][j] = 0;
            }
        }
    }

    int a, b;
    for (int i = 0; i < k; i++)
    {
        cin >> a >> b;
        d[a][b] = 1;
    }
    for (int i = 1; i < n + 1; i++)
    {
        for (int j = 1; j < m + 1; j++)
        {
            if (d[i][j] == 0)
            {
                bfs(d, i, j);
                z++;
            }
        }
    }

    cout << z;
    return 0;
}