#include <bits/stdc++.h>
#include <vector>
#include <sstream>
using namespace std;

int N,M,K;
int c;
vector<int> a,b,q;
vector<vector<int> > p;


void Upisi(int x, int y, int cloc)
{
    int i;
    p[y][x]=cloc;
    i=x+1;
    while ((i<=M) && (p[y][i]!=0)) i++;
    if (q[y]>=x) q[y]=i;
    if ((y>1) && (p[y-1][x]==0)) Upisi(x,y-1,cloc);
    if ((y<N) && (p[y+1][x]==0)) Upisi(x,y+1,cloc);
    if ((x>1) && (p[y][x-1]==0)) Upisi(x-1,y,cloc);
    if ((x<M) && (p[y][x+1]==0)) Upisi(x+1,y,cloc);
}
int main()
{
    int au,bu,j;
    cin >> N >> M >> K;
    vector<int> qtmp(N+1,1);
    q=qtmp;
    vector<vector<int> > ptmp(N+1,vector<int> (M+1, 0));
    p=ptmp;
    for (int i=1;i<=K;i++)
    {
        cin >> au >> bu;
        a.push_back(au);
        b.push_back(bu);
        p[au][bu]=1;
        if (q[au]==bu)
        {
            j=bu+1;
            while ((j<=M) && (p[au][j]!=0)) j++;
            q[au]=j;
        }

    }
    c=2;
    //for (int iz = 0; iz < p.size(); iz++) { for (int jz = 0; jz < p[iz].size(); jz++) { cout << p[iz][jz] << " "; } cout << endl; } for (int j = 0; j < q.size(); j++) { cout << q[j] << endl; }
    for (int i=1;i<=N;i++)
    while (q[i] <= M)
    {
        Upisi(q[i],i,c);
        c++;
    }
    cout << c-2 << endl;
    return 0;
}