#include <iostream>
#include <math.h>
#include <vector>
#define ll long long

using namespace std;

int main()
{
    int n, m, k, x, y, sum = 0;
    cin >> n >> m >> k;
    vector<vector<bool>>v(n);
    vector<pair<int,int>>p;

    for (int i = 0; i < n; i++)
        v[i].resize(m);

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

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (v[i][j])
                continue;

            else
            {
                sum++;
                v[i][j] = true;
                x = i;
                y = j;

                while (true)
                {
                    if (x > 0 && !v[x - 1][y])
                    {
                        v[x - 1][y] = true;
                        p.push_back({x - 1, y});
                    }

                    if (x < n - 1 && !v[x + 1][y])
                    {
                        v[x + 1][y] = true;
                        p.push_back({x + 1, y});
                    }

                    if (y > 0 && !v[x][y - 1])
                    {
                        v[x][y - 1] = true;
                        p.push_back({x, y - 1});
                    }

                    if (y < m - 1 && !v[x][y + 1])
                    {
                        v[x][y + 1] = true;
                        p.push_back({x, y + 1});;
                    }

                    if (!p.empty())
                    {
                        x = p[p.size() - 1].first;
                        y = p[p.size() - 1].second;
                        p.pop_back();
                    }

                    else
                        break;
                }
            }
        }
    }

    cout << sum;


    return 0;
}