#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

vp d = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};

vector<vi> vis;
int n, m;

bool ok(int x, int y){
	if (x >= 0 && y >= 0 && x < n && y < m && !vis[x][y])
		return 1;
	return 0;
}

void dfs(int i, int j){
	vis[i][j] = 1;

	for (auto& k : d){
		int x = i + k.first, y = j + k.second;

		if (ok(x, y)){
			dfs(x, y);
		}
	}
}

signed main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr); 
	cerr.tie(nullptr);	

	int  k;
	cin >> n >> m >> k;

	for (int i = 0; i < n; ++i){
		vi t(m, 0);
		vis.push_back(t);
	}

	for (int i = 0; i < k; ++i){
		int x, y;
		cin >> x >> y;

		vis[x - 1][y - 1] = 1;
	}


	int col = 0;
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < m; ++j){
			if (!vis[i][j]){
				dfs(i, j);
				++col;
			}
		}
	}
	cout << col << '\n';
}