#include <bits/stdc++.h>

/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define nul(x) memset((x),0,sizeof((x)))
#define random_jbt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

int d[1010][1010];
int c=1;
    int n,m,k;

void oboji(int a,int b){
    if (d[a][b]!=0 or a>n or b>m or a<1 or b<1)return;
    d[a][b]=c;
    oboji(a-1,b);
    oboji(a,b-1);
    oboji(a+1,b);
    oboji(a,b+1);
}

int main(){
    ios;
    nul(d);

    cin>>n>>m>>k;
    for (int i=1;i<=k;i++){
        int a,b;
        cin>>a>>b;
        d[a][b]=-1;
    }

    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            if (!d[i][j]){
                oboji(i,j);
                c++;
            }
        }
    }

    int ans=0;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            //cout<<d[i][j]<<" ";
            ans=max(ans,d[i][j]);
        }
        //cout<<"\n";
    }
    cout<<ans;
    return 0;
}