#include <bits/stdc++.h>

using namespace std;

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

    int N, M, K;
    cin >> N >> M >> K;

    bool matrix[N + 1][M + 1] = {};

    for(int i = 0; i < K; i++)
    {
        int a, b;
        cin >> a >> b;

        matrix[a][b] = true;
    }

    int colors = 0;


    for(int i = 1; i <= N; i++)
    {
        for(int j = 1; j <= M; j++)
        {
            if(matrix[i][j] != true)
            {
                colors++;

                queue<pair<int, int>> bfsQueue;
                bfsQueue.push(make_pair(i, j));
                matrix[i][j] = true;

                while(!bfsQueue.empty())
                {
                    int x = bfsQueue.front().first;
                    int y = bfsQueue.front().second;
                    bfsQueue.pop();
                    for(int j = -1; j <= 1; j++)
                    {
                        for(int k = -1; k <= 1; k++)
                        {
                            if((j == 0) ^ (k == 0))
                            {
                                if(x + j <= N && x + j >= 1 && y + k >= 1 && y + k <= M)
                                {
                                    if(!matrix[x + j][y + k])
                                    {
                                        bfsQueue.push(make_pair(x + j, y + k));
                                        matrix[x + j][y + k] = true;
                                    }

                                }
                            }
                        }
                    }
                }
            }
        }
    }

    cout << colors << endl;
    return 0;
}