#include <bits/stdc++.h>
using namespace std;
#define MAXN 10000000002
int n,m;
vector <vector<int> > Graph;
map<pair<int,int>,int> IndexOf;
int Index(pair <int,int> A){
    int index=0;
if(IndexOf[A]==0){
    index=Graph.size()+1;
    IndexOf[A]=Graph.size()+1;
    Graph.push_back(vector <int>());
}
else index=IndexOf[A];
return index-1;
}
bool OK(pair<int,int> A){
if(A.first<0||A.second<0||A.first>n||A.second>m)return 0;
return 1;
}
vector <pair<int,int> > Later[4];

///0 - (0,0) - (n,0)
///1 - (0,0) - (0,m)
///2 - (n,0) - (n,m)
///3 - (0,m) - (n,m)
bool StoreIvica(pair<int,int> A,pair<int,int> B){

    ///1 if ivica.
    bool ret=0;
    if(A==B)cout <<"FATAL ERROR!"<<endl;
    if(A.first==B.first){
        int index=-1;
        if(A.first==0)index=1;
        if(A.first==n){
            index=2;
        }
        if(index!=-1){
            Later[index].push_back(A);
            Later[index].push_back(B);

            ret=1;
        }
    }
    if(A.second==B.second){
        int index=-1;
        if(A.second==0)index=0;
        if(A.first==m){
            index=3;
        }
        if(index!=-1){
            Later[index].push_back(A);
            Later[index].push_back(B);

            ret=1;
        }

    }
    //if(ret==1)cout <<"ivicaa!!!"<<endl;
    return ret;


}
void Connect(pair<int,int> A,pair <int,int> B,bool sudo=false){
if(!OK(A)||!OK(B))return;
if(!sudo){
    if(StoreIvica(A,B))return;

}
int indexA=Index(A);
int indexB=Index(B);
//cout <<indexA<<" "<<indexB<<endl;
Graph[indexA].push_back(indexB);
Graph[indexB].push_back(indexA);
}
int Resi(int k){
int N=Graph.size();
int V=0;
for(int i=0;i<N;i++) {
    V+=Graph[i].size();
}
V/=2;///V-E+F=2
return 1-N+V-k;
}

void ConnectArray(vector <pair<int,int> > &Array,pair<int,int> A,pair<int,int> B){//Array is sorted
    if(!Array.size()||Array[Array.size()-1]!=B)Array.push_back(B);
    if(!Array.size()||Array[0]!=A)Array.push_back(A);
    sort(Array.begin(),Array.end());


    for(int i=1;i<Array.size();i++){
        if(Array[i]!=Array[i-1])
            Connect(Array[i],Array[i-1],true);
    }

}
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);


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

    pair <int,int> Leva[4]={{0,0},{0,0},{n,0},{0,m}};
    pair <int,int> Desna[4]={{n,0},{0,m},{n,m},{n,m}};

    for(int i=0;i<k;i++){
        int x,y;
        cin >>x>>y;
        x--;
        y--;
        Connect({x,y},{x+1,y});
        Connect({x+1,y},{x+1,y+1});
        Connect({x+1,y+1},{x,y+1});
        Connect({x,y+1},{x,y});
    }

    for(int i=0;i<4;i++){
        sort(Later[i].begin(),Later[i].end());
        // cout <<Desna[i].first<<" "<<Desna[i].second<<endl;
        ConnectArray(Later[i],Leva[i],Desna[i]);


    }
/*
    for(int i=0;i<Graph.size();i++){cout <<i<<" : ";
        for(int j=0;j<Graph[i].size();j++){
        cout <<" "<<Graph[i][j]<<",";
        }cout <<endl;
    }*/

cout <<Resi(k)<<endl;
}