#include <bits/stdc++.h>

using namespace std; 

int mat[1000][1000];
int p = 0;
void bfs(int n, int m, int k, int xs, int ys)
{
	p++;
	queue< pair<int,int> > q;
	if(mat[xs][ys] == -1) return;
	q.push({xs,ys});
	while(!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		mat[x][y] = p;
		if(x-1 > 0  && mat[x-1][y] == 0) {
			q.push({x-1,y});
		}
		if(y-1 > 0  && mat[x][y-1] == 0) {
			q.push({x,y-1});
		}
		if(x+1 < n  && mat[x+1][y] == 0) {
			q.push({x+1,y});
		}
		if(y+1 < m  && mat[x][y+1] == 0) {
			q.push({x,y+1});
		}
		q.pop();
	}
}

int main () {
	int n,m,k;
	cin >> n >> m >> k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin >> a >> b;
		mat[a-1][b-1] = -1;
	}
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if(mat[i][j] == 0)
			bfs(n,m,k,i,j);
		}
	}
	
	cout << p << endl;
}