#include <iostream>
#include <vector>

using namespace std;




int sigurno(vector<vector<int>> & M, int row, int col, vector < vector<bool>> & visited, int maxn, int maxm)
{
	return (row >= 0) && (row < maxn) && (col >= 0) && (col < maxm) && (M[row][col] && !visited[row][col] ) ;
};

void oboj(vector<vector<int>>& M, int row, int col, vector < vector<bool>>& visited, int maxn, int maxm)
{

	static int rowNbr[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int colNbr[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

	visited[row][col] = true;

	for (int k = 0; k < 8; ++k)
		if (sigurno(M, row + rowNbr[k], col + colNbr[k], visited, maxn, maxm))
			if ((rowNbr[k] + colNbr[k] != 0) && (rowNbr[k] + colNbr[k] != 2) && (rowNbr[k] + colNbr[k] != -2)) {
				oboj(M, row + rowNbr[k], col + colNbr[k], visited, maxn, maxm);
			}
}


int prebroj(vector<vector<int>> & M,const int n, const int m)
{

	vector < vector<bool>> visited;
	vector<bool> raw;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			raw.push_back(0);
		}
		visited.push_back(raw);
	}
	
	int count = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if (M[i][j] && !visited[i][j]) {
 
				oboj(M, i, j, visited, n, m);

				++count;
			}

	return count;
};

int main()
{
	int n, m, br,r;
	int v, k;
	//int tabla[ROW][COL];
	vector < vector<int>> tabla;
	vector<int> raw;
	
	br = 0;
	n = 0;
	m = 0;


	cin >>n >> m >> br;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			//cout << i << " " << j << endl;
			raw.push_back(1);
		}
		tabla.push_back(raw);
	}

	for(int i = 0; i < br; ++i) {
		cin >> v >> k;
		tabla[v-1][k-1] = 0;
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; j++) {
			//cout << tabla[i][j];
		}
		//cout <<" "<< endl;
	}
	
	r = prebroj(tabla,n,m);

	cout << r;
	return 0;
}