#include <bits/stdc++.h>
#define maxn 1010
using namespace std;

bool was[maxn][maxn];
int n, m, k, ans, d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

void dfs(int x, int y){
    was[x][y] = 1;
	for(int i = 0; i < 4; ++i){
		int x1 = x + d[i][0], y1 = y + d[i][1];
		if(x1 >= 0 and x1 < n and y1 < m and y1 >= 0 and !was[x1][y1]){
			dfs(x1, y1);
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	cin >> n >> m >> k;
	for(int i = 0; i < k; ++i){
		int x, y;
		cin >> x >> y;
		x--, y--;
		was[x][y] = 1;
	}
	int ans = 0;
	for(int i = 0; i < n; ++i){
		for(int j =0 ;j  < m; ++j){
			if(!was[i][j]){
				++ans;
				dfs(i, j);
			}
		}
	}
	cout << ans;
}