#include <bits/stdc++.h>
#define ll long long
#define endl "\n"

bool visited[36000000];
bool crna[36000000];

using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);


int n,m,k;
cin >> n >> m >> k;

for (int i=0; i<k; i++)
{
    int y,x;
    cin >> y >> x;
    y--; x--;
    ll korda=y*m+x;
    crna[korda]=true;
}
int sol=0;

for (int i=0; i<n*m; i++)
{
    if (!visited[i] && !crna[i])
    {
        list <ll> q;
        q.push_back(i);

        while (!q.empty())
        {
            ll korda=q.front();
            visited[korda]=true;
            q.pop_front();
            ll y=korda/m;
            ll x=korda%m;
            if (y>0) { ll smurf=(y-1)*m+x; if (visited[smurf]==false && crna[smurf]==false) q.push_back(smurf); }
            if (y<n-1) { ll smurf=(y+1)*m+x; if (visited[smurf]==false && crna[smurf]==false) q.push_back(smurf); }
            if (x>0) { ll smurf=y*m+x-1; if (visited[smurf]==false && crna[smurf]==false) q.push_back(smurf); }
            if (x<m-1) { ll smurf=y*m+x+1; if (visited[smurf]==false && crna[smurf]==false) q.push_back(smurf); }
        }
    sol++;
    }
}

cout << sol;

}