/*
ID: 18126251
LANG: C++
TASK: 
*/
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <time.h>
#include <queue>

using namespace std;

const int maxn = 1005;
const int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int w, h, n;
int x1[maxn], x2[maxn], y1[maxn], y2[maxn];
int vis[maxn*3][maxn*3];

int comp(int *x1, int *x2, int w){
	std::vector<int> v;
	for(int i = 0; i < n; i++){
		for(int j = -1; j <= 1; j++){
			if(0 <= x1[i]+j && x1[i] + j < w) v.push_back(x1[i]+j);
			if(0 <= x2[i] + j && x2[i] + j < w) v.push_back(x2[i]+j);
		}
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	for(int i = 0; i < n; i++){
		x1[i] = lower_bound(v.begin(), v.end(), x1[i]) - v.begin();
		x2[i] = lower_bound(v.begin(), v.end(), x2[i]) - v.begin();
	}
	return v.size();
}

void bfs(int y, int x){
	queue<pair<int, int> >q;
	q.push(make_pair(y, x));
	vis[y][x] = 1;
	while(!q.empty()){
		int sy = q.front().first, sx = q.front().second;
		q.pop();
		for(int i = 0; i < 4; i++){
			int tx = sx + d[i][0], ty = sy + d[i][1];
			if(0 <= tx && tx < w && 0 <= ty && ty < h && !vis[ty][tx]){
				vis[ty][tx] = 1;
				q.push(make_pair(ty, tx));
			}
		}
	}
}



int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
#endif
	// clock_t start = clock();
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(cin >> w >> h && w){
		cin >> n;
		for(int i = 0; i < n; i++){
			cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		}

		w = comp(x1, x2, w); 
		h = comp(y1, y2, h);

		for(int y = 0; y < h; y++){
			for(int x = 0; x < h; x++){
				vis[y][x] = 0;
			}
		}
		for(int i = 0; i < n; i++){
			for(int y = y1[i]; y < y2[i]; y++){
				for(int x = x1[i]; x < x2[i]; x++){
					vis[y][x] = 1;
				}
			}
		}


		int ans = 0;
		for(int y = 0; y < h; y++){
			for(int x = 0; x < w; x++){
				if(!vis[y][x]){
					ans++;
					bfs(y, x);
				}
			}
		}
		cout << ans << endl;
	}

	// clock_t ends = clock();
    // cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << endl;
	return 0;
}
