#include <bits/stdc++.h>

using namespace std;
#define MAX 1001
int a[MAX][MAX];
bool visited[MAX][MAX];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int n,m,k;

void dfs(int x,int y)
{
    if(visited[x][y])return ;
    visited[x][y]=true;
    for(int i = 0; i < 4; i++)
    {
        int xx = x+dx[i];
        int yy = y+dy[i];
        if(xx <= 0 || yy <= 0)continue;
        if(xx > n || yy > m)continue;
        if(a[xx][yy]==1)continue;
        dfs(xx,yy);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m >> k;
    for(int i = 0; i < k; i++)
    {
        int x,y;
        cin >> x >> y;
        a[x][y]=1;
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(!visited[i][j] && a[i][j]==0)
            {
                dfs(i,j);
                cnt++;
            }
        }
    }
    cout << cnt;
    return 0;
}