#include <bits/stdc++.h>

using namespace std;

int n,m;
int k;
int vis[1005][1005];
int por[] = {1,-1,0,0,1,1,-1,-1};
int pok[] = {0,0,-1,1,-1,1,-1,1};
int mat[1005][1005];
set<pair<int,int>> crne;
set<pair<int,int>> poseceno;
bool bilakomp;
set<pair<int,int>> bele;
int sol;
int komp;

void bfs(int sr,int sk)
{
    queue<pair<int,int>> q;
    q.push({sr,sk});
    vis[sr][sk] = 1;
    
    while(!q.empty())
    {
        pair<int,int> p = q.front();
        int rr = p.first;
        int kk = p.second;
        q.pop();
        for(int i=0;i<4;i++)
        {
            int nr = rr + por[i];
            int nk = kk + pok[i];
            if(nr>=1 && nr<=n && nk>=1 && nk<=m && mat[nr][nk]==1 && vis[nr][nk]==0)
            {
                vis[nr][nk] = 1;
                q.push({nr,nk});
            }
        }
    }
}

bool barjedancrni(int rr,int kk)
{
    for(int i=0;i<8;i++)
    {
        int nr = rr + por[i];
        int nk = kk + pok[i];
        set<pair<int,int>>::iterator it;
        it = crne.find({nr,nk});
        if(it!=crne.end()) return true;
    }
    
    return false;
}

void sredibelo(int rr,int kk)
{
    //cout << "BELO" << "\n";
    //cout << rr << " " << kk << "\n";
    bele.insert({rr,kk});
    for(int i=0;i<4;i++)
    {
        int nr = rr + por[i];
        int nk = kk + pok[i];
        set<pair<int,int>>::iterator it,it2;
        if(!(nr>=1 && nr<=n && nk>=1 && nk<=m)) continue;
        it = crne.find({nr,nk});
        it2 = bele.find({nr,nk});
        if(it==crne.end() && it2==bele.end() && barjedancrni(nr,nk))
        {
            sredibelo(nr,nk);
        }
    }
}

void obidji(int rr,int kk)
{
    //cout << "CRNO" << "\n";
    //cout << rr << " " << kk << "\n";
    poseceno.insert({rr,kk});
    for(int i=0;i<4;i++)
    {
        int nr = rr + por[i];
        int nk = kk + pok[i];
        set<pair<int,int>>::iterator it,it2;
        if(!(nr>=1 && nr<=n && nk>=1 && nk<=m)) continue;
        it = crne.find({nr,nk});
        it2 = bele.find({nr,nk});
        if(it==crne.end() && it2==bele.end())
        {
            komp++;
            sredibelo(nr,nk);
        }
    }
    
    for(int i=0;i<8;i++)
    {
        int nr = rr + por[i];
        int nk = kk + pok[i];
        set<pair<int,int>>::iterator it,it2;
        if(!(nr>=1 && nr<=n && nk>=1 && nk<=m)) continue;
        it = crne.find({nr,nk});
        it2 = poseceno.find({nr,nk});
        if(it!=crne.end() && it2==poseceno.end())
        {
            obidji(nr,nk);
        }
    }
    
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    
    cin >> n >> m >> k;
    
    if(n<=1 && m<=1)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                mat[i][j] = 1;
                vis[i][j] = 0;
            }
        }
        for(int i=1;i<=k;i++)
        {
            int x,y;
            cin >> x >> y;
            mat[x][y] = 0;
        }
        
        int cnt = 0;
        
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(mat[i][j]==1 && vis[i][j]==0)
                {
                    bfs(i,j);
                    cnt++;
                }
            }
        }
        
        cout << cnt;
    }
    else
    {
        sol = 0;
        
        for(int i=1;i<=k;i++)
        {
            int x,y;
            cin >> x >> y;
            crne.insert({x,y});
        }
        
        for(pair<int,int> p : crne)
        {
            set<pair<int,int>>::iterator it;
            it = poseceno.find(p);
            if(it==poseceno.end())
            {
                bele.clear();
                komp = 0;
                obidji(p.first,p.second);
                if(bilakomp) sol+=komp-1;
                else
                {
                    bilakomp = true;
                    sol+=komp;
                }
            }
        }
        
        cout << sol;
        
    }
    
    return 0;
}