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

// for 20 points

vector<vector<bool>> mat1;

void pretraga(int Y, int X, int N, int M){
    // note in if, if you check value
    // before you check if it is out side range
    // you get segment dump
	if(X < 0 || Y < 0 || X > N - 1 || Y > M - 1 || !mat1[Y][X]) return;
    
    	mat1[Y][X] = false;
    
    	pretraga(X + 1, Y, M, N);
    	pretraga(X, Y + 1, M, N);
    	pretraga(X - 1, Y, M, N);
    	pretraga(X, Y - 1, M, N);
}


int main(){
	int N, M, K; cin >> N >> M >> K;
	int sol = 0;

	for(int i = 0; i < M; i++){
		vector<bool> temp(N, true);
		mat1.push_back(temp);
	}
	for(int i = 0; i < K; i++){
		int X, Y; cin >> X >> Y;
		mat1[X-1][Y-1] = false;
	}
     	for (int i = 0; i < M; i++){
        	for (int j = 0; j < N; j++) {
			if(mat1[i][j]){
				sol++;
                		pretraga(i, j, N, M);
			}
			else continue;
            	}
	}	
	cout << sol << endl;
	return 0;
}