#include <bits/stdc++.h>

using namespace std;

long long sol=0;
set<pair<long long, long long>> crne;
set<pair<long long, long long>> visited;
long long n,m,k;

void bfs(long long x, long long y) 
{ 
    queue<pair<long long, long long>> q; 
  
    q.push(make_pair(x,y)); 
    visited.emplace(make_pair(x,y));
  
    while (!q.empty()) { 
  
        pair<long, long> f = q.front(); 
        q.pop(); 
  
        //cout << f.first << " " << f.second << endl; 
  
        if(f.first-1>=0 && visited.find(make_pair(f.first-1, f.second))==visited.end() && crne.find(make_pair(f.first-1,f.second))==crne.end())
        {
            q.push(make_pair(f.first-1, f.second));
            visited.emplace(make_pair(f.first-1, f.second));
        }
        if(f.first+1<n && visited.find(make_pair(f.first+1, f.second))==visited.end() && crne.find(make_pair(f.first+1,f.second))==crne.end())
        {
            q.push(make_pair(f.first+1, f.second));
            visited.emplace(make_pair(f.first+1, f.second));
        }
        if(f.second-1>=0 && visited.find(make_pair(f.first, f.second-1))==visited.end() && crne.find(make_pair(f.first,f.second-1))==crne.end())
        {
            q.push(make_pair(f.first, f.second-1));
            visited.emplace(make_pair(f.first, f.second-1));
        }
        if(f.second+1<m && visited.find(make_pair(f.first, f.second+1))==visited.end() && crne.find(make_pair(f.first,f.second+1))==crne.end())
        {
            q.push(make_pair(f.first, f.second+1));
            visited.emplace(make_pair(f.first, f.second+1));
        }    
    } 
} 
  

int main()
{
    cin >> n >> m >> k;
    
    for(long long i=0;i<k;i++)
    {
        long long x, y;
        cin >> x >> y;
        crne.emplace(make_pair(x-1,y-1));
    }
    for(long long i=0;i<n;i++)
    {
        for(long long j=0;j<m;j++)
        {
            if(visited.find(make_pair(i,j))==visited.end() && crne.find(make_pair(i,j))==crne.end())
            {
                bfs(i,j);
                sol++;
                //cout << sol << endl;
            }
        }
    }
    cout << sol << endl;
    return 0;
}