#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> p;
const int K = 1e5+2;
const int N = 9005;

int n,m,k;
bool bio[N][N];

void prvi(){
    for(int i = 1; i <= k; i++){
        int u,v;
        scanf("%i%i",&u,&v);
        bio[u][v] = 1;
    }
    int br = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(bio[i][j]){
                continue;
            }
            queue <p> q;
            q.push(p(i,j));
            bio[i][j] = 1;
            while(!q.empty()){
                p x = q.front();
                q.pop();
                if(x.first > 1 && !bio[x.first-1][x.second]){
                    q.push(p(x.first-1,x.second));
                    bio[x.first-1][x.second] = 1;
                }
                if(x.first < n && !bio[x.first+1][x.second]){
                    q.push(p(x.first+1,x.second));
                    bio[x.first+1][x.second] = 1;
                }
                if(x.second > 1 && !bio[x.first][x.second-1]){
                    q.push(p(x.first,x.second-1));
                    bio[x.first][x.second-1] = 1;
                }
                if(x.second < m && !bio[x.first][x.second+1]){
                    q.push(p(x.first,x.second+1));
                    bio[x.first][x.second+1] = 1;
                }
            }
            br++;
        }
    }
    cout << br << endl;
}

const int A = 1e6+5;

vector <p> crni;
map <p,bool> crn,sta;
map <p,int> broj;
p vrati[A];
int cnt = 0;

void dodajcvor(int u,int v){
    if(u < 1 || u > n || v < 1 || v > m){
        return;
    }
    if(crn.count(p(u,v))){
        return;
    }
    if(!broj.count(p(u,v))){
        broj[p(u,v)] = ++cnt;
        vrati[cnt] = p(u,v);
    }
}

void sranje(){
    for(int i = 1; i <= k; i++){
        int u,v;
        scanf("%i%i",&u,&v);
        crni.push_back(p(u,v));
        crn[p(u,v)] = 1;
    }
    for(int i = 1; i <= k; i++){
        int u = crni[i-1].first,v = crni[i-1].second;
        dodajcvor(u-1,v-1);
        dodajcvor(u-1,v);
        dodajcvor(u-1,v+1);

        dodajcvor(u,v-1);
        dodajcvor(u,v+1);

        dodajcvor(u+1,v-1);
        dodajcvor(u+1,v);
        dodajcvor(u+1,v+1);
    }
    int br = 0;
    for(int i = 1; i <= cnt; i++){
        if(sta.count(p(vrati[i].first,vrati[i].second))){
            continue;
        }
        queue <int> q;
        q.push(i);
        while(!q.empty()){
            int u = q.front();
            q.pop();
            int x = vrati[u].first,y = vrati[u].second;
            if(broj.count(p(x-1,y)) && !sta.count(p(x-1,y))){
                q.push(broj[p(x-1,y)]);
                sta[p(x-1,y)] = 1;
            }
            if(broj.count(p(x+1,y)) && !sta.count(p(x+1,y))){
                q.push(broj[p(x+1,y)]);
                sta[p(x+1,y)] = 1;
            }
            if(broj.count(p(x,y-1)) && !sta.count(p(x,y-1))){
                q.push(broj[p(x,y-1)]);
                sta[p(x,y-1)] = 1;
            }
            if(broj.count(p(x,y+1)) && !sta.count(p(x,y+1))){
                q.push(broj[p(x,y+1)]);
                sta[p(x,y+1)] = 1;
            }
        }
        br++;
    }
    cout << br << endl;
}

int main(){
    scanf("%i%i%i",&n,&m,&k);
    if(n <= 9000 && m <= 9000){
        prvi();
        return 0;
    }
    sranje();
}