#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 10005;	
int n, m, k;
int mat[maxn][maxn];
bool visited[maxn][maxn];
int jedan[4] = {-1, 1, 0, 0};
int dva[4] = {0, 0, -1, 1};
int moze(int x, int y){
	return (x >= 0) && (x < n) && (y >= 0) && (y < m) && (!mat[x][y]) && (!visited[x][y]);
}
void dfs(int x, int y){
	visited[x][y] = 1;
	for(int i=0;i<4;i++){
		int nova = x + jedan[i], nova1 = y + dva[i];
		if(moze(nova, nova1))dfs(nova, nova1);
	}
}
int boje(){
	int brojac = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(!mat[i][j] && !visited[i][j]){
				dfs(i,j);
				brojac++;
			}
		}
	}
	return brojac;
}
int main()
{
	cin >> n >> m >> k;
	for(int i=0;i<k;i++){
		int x, y;
		cin >> x >> y;
		x--, y--;
		mat[x][y] = 1;
	}	
	cout << boje() << endl;
	return 0;
}