#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool crno[1001][1001],vis[1001][1001];
vector<pair<int,int> > susedi[1001][1001];
void dfs(int i,int j)
{
    if(vis[i][j]==true)
        return;
    else
    {
        int k;
        vis[i][j]=true;
        for(k=0;k<susedi[i][j].size();k++)
            dfs(susedi[i][j][k].first,susedi[i][j][k].second);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m,k,i,a,b,j;
    long long br=0;
    cin >> n >> m >> k;
    for(i=1;i<=k;i++)
    {
        cin >> a >> b;
        crno[a][b]=true;
    }
    if(n*m<=2000000)
    {
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(crno[i][j]==false)
                {
                    if(i>1 && crno[i-1][j]==false)
                        susedi[i][j].push_back(make_pair(i-1,j));
                    if(i<n && crno[i+1][j]==false)
                        susedi[i][j].push_back(make_pair(i+1,j));
                    if(j>1 && crno[i][j-1]==false)
                        susedi[i][j].push_back(make_pair(i,j-1));
                    if(j<m && crno[i][j+1]==false)
                        susedi[i][j].push_back(make_pair(i,j+1));
                }

            }
        }
        for(i=1;i<=n;i++)
            for(j=1;j<=m;j++)
            {
                //cout << vis[i][j] << " " << crno[i][j] << endl;
                if(vis[i][j]==false && crno[i][j]==false)
                {
                    br++;
                    dfs(i,j);
                }
            }
        cout << br;
    }
    //cout << "Hello world!" << endl;
    return 0;
}