#include <bits/stdc++.h>
using namespace std;
#define MAXN 10000000002
int n,m;
vector <vector<int> > Graph;
map<pair<int,int>,int> IndexOf;

bool OK(pair<int,int> A){
if(A.first<0||A.second<0||A.first>n||A.second>m)return 0;
return 1;
}

int Index(pair <int,int> A){
    if(!OK(A))return -1;
    int index=IndexOf[A];
//cout <<"INDEX: "<<index<<endl;
if(index==0){
    Graph.push_back(vector <int>(0));
    index=Graph.size();
    IndexOf[A]=Graph.size();

}

return index-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 status=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);

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

            status=1;
        }

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


}
void Connect(pair<int,int> A,pair <int,int> B,bool sudo=false){
if(!OK(A)||!OK(B))return;
int indexA=Index(A);
int indexB=Index(B);
//cout <<"CONNECTING : ("<<A.first<<","<<A.second<<"); ("<<B.first<<","<<B.second<<")...: ";
if(!sudo){
    if(StoreIvica(A,B)){//cout <<"FAILED"<<endl;
            return;}

}

//cout <<indexA<<" "<<indexB<<endl;
//cout <<"SUCCESSFUL"<<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++) {
    sort(Graph[i].begin(),Graph[i].end());
    V++;
    for(int j=1;j<Graph[i].size();j++){
        if(Graph[i][j]!=Graph[i][j-1])V++;
    }
}
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);
    }

}
vector <int> Bio;
void DFS(int index,int color=1){
if(Bio[index]!=0)return;
Bio[index]=color;
for(auto nod:Graph[index])DFS(nod,color);
}
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]={make_pair(0,0),make_pair(0,0),make_pair(n,0),make_pair(0,m)};
    pair <int,int> Desna[4]={make_pair(n,0),make_pair(0,m),make_pair(n,m),make_pair(n,m)};
    vector <pair<int,int> > Crni;
    for(int i=0;i<k;i++){
        int x,y;
        cin >>x>>y;
        x--;
        y--;
        Connect(make_pair(x,y),make_pair(x+1,y));
        Connect(make_pair(x+1,y),make_pair(x+1,y+1));
        Connect(make_pair(x+1,y+1),make_pair(x,y+1));
        Connect(make_pair(x,y+1),make_pair(x,y));
        Crni.push_back(make_pair(x,y));
       // cout <<(pair<int,int>)({x,y}).first<<" "<<(pair<int,int>)({x,y}).second<<endl;
       // cout <<Graph.size()<<endl;
    }




    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]);


    }
    Bio.resize(Graph.size());
    int color=1;
    for(int i=0;i<Bio.size();i++){
        if(Bio[i]==0)DFS(i,color++);
    }
    for(int i=0;i<Crni.size();i++){
        if(Bio[Index(Crni[i])]!=Bio[Index(make_pair(0,0))])k--;
    }

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