#include <bits/stdc++.h>
using namespace std;
#define MAX 1002

bool maze[MAX][MAX];
int br=0,n,m;

bool safe(int x, int y)
{
    if(x==n || y==m || x<0 || y<0 || maze[x][y]==false) return false;
    return true;
}
void popuni(int x, int y)
{
    maze[x][y]=false;
    if(safe(x+1,y)) popuni(x+1,y);
    if(safe(x,y+1)) popuni(x,y+1);
    if(safe(x-1,y)) popuni(x-1,y);
    if(safe(x,y-1)) popuni(x,y-1);
}
void solve()
{
    for(int i=0; i<n; ++i) {
        for(int j=0; j<m; ++j) {
            if(maze[i][j]==true) { br++; popuni(i,j); }
        }
    }
    cout<<br;
}

int main()
{

    int k;
    cin>>n>>m>>k;
    for(int i=0; i<n; ++i) {
        for(int j=0; j<m; ++j) {
            maze[i][j]=true;
        }
    }
    int x,y;
    while(k--) {
        cin>>x>>y;
        x--; y--;
        maze[x][y]=false;
    }
    solve();
    return 0;
}