#include <bits/stdc++.h>
#define f first
#define s second

using namespace std;
typedef long long ll;
ll col, n, m, k;
map<pair<int,int>,pair<int,int>> from;
map<pair<int,int>,bool> vis, black, calc;
map<pair<pair<int,int>,pair<int,int>>,bool> cc;
vector<int> dx, dy;
map<pair<int,int>,bool> vis2, mat;

bool valid(pair<int,int> z)
{   return z.f>=0 && z.s>=0 && z.f<=n+1 && z.s<=m+1;    }
bool valid2(pair<int,int> z)
{   return z.f>0 && z.s>0 && z.f<=n && z.s<=m;    }
bool neigh(pair<int,int> a, pair<int,int> b)
{   return abs(a.f-b.f)<=1 && abs(a.s-b.s)<=1;  }
bool realneigh(pair<int,int> a,pair<int,int> b)
{   return abs(a.f-b.f)!=1 || abs(a.s-b.s)!=1;  }
bool calcblack(pair<int,int> a)
{
    pair<int,int> b;
    for(int i=0;i<8;i++) {
        b.f=a.f+dx[i], b.s=a.s+dy[i];
        if(black[b]&&calc[b]) return true;
    }
    return false;
}
bool check(pair<int,int> ct, pair<int,int> t, pair<int,int> fromct, pair<int,int> fromt)
{
    vector<pair<int,int>> a;
    a.push_back(ct); a.push_back(t);
    a.push_back(fromct); a.push_back(fromt);
    sort(a.begin(),a.end());
    if(a[1].f==a[0].f+1 && a[2].f==a[1].f && a[3].f==a[0].f &&
       a[1].s==a[0].s-1 && a[2].s==a[0].s && a[3].s==a[0].s+1)
       return false;
    if(a[0].f==a[1].f && a[0].f==a[2].f && a[3].f==a[0].f+1 &&
       a[0].s==a[1].s-1 && a[1].s==a[2].s-1 && a[3].s==a[1].s)
        return false;
    if(a[0].f==a[1].f&&a[1].f==a[2].f-1&&a[2].f==a[3].f &&
       a[0].s==a[2].s&&a[2].s==a[1].s-1&&a[1].s==a[3].s)
        return false;
    return true;
}


void bfs(pair<int,int> z)
{
    vis[z]=true;
    queue<pair<int,int>> q;
    q.push(z);
    while(!q.empty()) {
        pair<int,int> t, ct;
        t = ct = q.front(); q.pop();
        for(int i=0;i<8;i++) {
            ct.f=t.f+dx[i]; ct.s=t.s+dy[i];
            if(black[ct]) {
                if(!vis[ct])
                    vis[ct]=1, from[ct]=t, q.push(ct);
                /*else if(from[ct]!=from[t] && !neigh(from[ct],from[t]) && realneigh(t,ct) && !calc[t])
                    calc[from[ct]]=calc[from[t]]=calc[t]=calc[ct]=1, col++;*/
                /*else if(from[ct]!=from[t] && (!neigh(from[ct],from[t])||!realneigh(from[ct],t))&&(!calc[ct]||!calc[t]))
                    col++, calc[ct]=calc[t]=1;*/
                else if(((realneigh(ct,t)&&!realneigh(from[ct],from[t]))
                         || (!realneigh(ct,t)&&!neigh(from[ct],from[t])&&(!calcblack(t)||!calcblack(ct))))
                        &&!calc[ct]&&!calc[t]&&check(ct,t,from[ct],from[t]))
                    col++, calc[ct]=true, calc[t]=true, calc[from[ct]]=true, calc[from[t]]=true;
            }
        }
    }
}

void dfs(pair<int,int> x)
{
    pair<int,int> a=x;
    if(!valid2(x)||vis[x]||mat[x]) return;
    vis[a]=true;
    a.f=x.f-1;
    if(!vis2[a]&&!mat[a]&&valid2(a))
        vis2[a]=true, dfs(a);
    a.f=x.f+1;
    if(!vis2[a]&&!mat[a]&&valid2(a))
        vis2[a]=true, dfs(a);
    a.f=x.f; a.s=x.s-1;
    if(!vis2[a]&&!mat[a]&&valid2(a))
        vis2[a]=true; dfs(a);
    a.s=x.s+1;
    if(!vis2[a]&&!mat[a]&&valid2(a))
        vis2[a]=true; dfs(a);
}

void solution2(vector<pair<int,int>> &x)
{
    for(int i=0;i<x.size();i++)
        mat[x[i]]=true, vis2[x[i]]=true;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) {
            pair<int,int> a={i,j};
            if(!mat[a]&&!vis2[a])
                vis2[a]=true, col++, dfs(a);
        }
}

int main()
{
    int a, b;
    scanf("%lld%lld%lld",&n,&m,&k);
    dx = {-1,1,0,0,-1,-1,1,1,0};
    dy = {0,0,-1,1,-1,1,-1,1,0};
    vector<pair<int,int>> x(k);
    for(int i=0;i<k;i++)
        scanf("%d%d",&x[i].f,&x[i].s),
        black[x[i]]=true;

    for(int i=0;i<=n+1;i++)
        x.push_back({i,0}), black[{i,0}]=1,
        x.push_back({i,m+1}), black[{i,m+1}]=1;
    for(int i=0;i<=m+1;i++)
        x.push_back({0,i}), black[{0,i}]=1,
        x.push_back({n+1,i}), black[{n+1,i}]=1;
    if(n*m<=1e7) {
        solution2(x);
        cout << col << endl;
        return 0;
    }
    bfs({0,0});
    for(int i=0;i<x.size();i++)
        if(!vis[x[i]])
            bfs(x[i]);
    printf("%lld",col);
    return 0;
}