import std.stdio;
import std.algorithm;
import std.math;
import core.stdc.stdio;

int[int] compCoord(ref int[] data){
	data.sort;
	int[int] ret;
	int c=0;
	foreach(i,d;data){
		if((d in ret) is null){
			ret[d] = c;
			data[c++] = d;
		}
	}
	data = data[0..c];
	return ret;
}
void main(){
	while(1){

	int w,h;
	scanf("%d%d",&w,&h);
	if(h==0&&w==0)
		break;
	
	int n;
	scanf("%d",&n);
	int size=n*2+2;
	int[] xs = new int[size];
	int[] ys = new int[size];
	struct rect{
		int x1;
		int y1;
		int x2;
		int y2;
	}
	rect[] rs = new rect[n];
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&rs[i].x1,&rs[i].y1,&rs[i].x2,&rs[i].y2);
		xs[i*2] = rs[i].x1;
		xs[i*2+1] = rs[i].x2;
		ys[i*2] = rs[i].y1;
		ys[i*2+1] = rs[i].y2;
	}
	xs[n*2] = 0;
	xs[n*2+1] = w;
	ys[n*2] = 0;
	ys[n*2+1] = h;
	
	int[int] xc = xs.compCoord;
	int[int] yc = ys.compCoord;
	
	int[] imos = new int[xs.length*ys.length];
	foreach(r;rs){
		int cx1 = xc[r.x1];
		int cy1 = yc[r.y1];
		int cx2 = xc[r.x2];
		int cy2 = yc[r.y2];
		imos[cy1*xs.length+cx1]++;
		imos[cy1*xs.length+cx2]--;
		imos[cy2*xs.length+cx1]--;
		imos[cy2*xs.length+cx2]++;
	}
	for(int i=0;i<ys.length;i++){
		int last=0;
		for(int j=0;j<xs.length;j++){
			imos[i*xs.length+j]+=last;
			last = imos[i*xs.length+j];
		}
	}
	for(int i=0;i<xs.length;i++){
		int last=0;
		for(int j=0;j<ys.length;j++){
			imos[i+j*xs.length]+=last;
			last = imos[i+j*xs.length];
		}
	}
	int ans=0;
	bool[] visited = new bool[xs.length*ys.length];
	int[] dx = [0,-1,0,1];
	int[] dy = [-1,0,1,0];
	int[2][] queue = new int[2][xs.length*ys.length];
	int BFS(int y,int x){
		if(visited[y*xs.length+x] || imos[y*xs.length+x] != 0)
			return 0;
		int qc=0;
		queue[qc++] = [y,x];
		visited[y*xs.length+x]=true;
		for(int i=0;i<qc;i++){
			int py = queue[i][0];
			int px = queue[i][1];
			for(int k=0;k<4;k++){
				int ny = py+dy[k];
				int nx = px+dx[k];
				if(0<=ny&&ny<ys.length&&ys[ny]<h&&0<=nx&&nx<xs.length&&xs[nx]<w){
					if(!visited[ny*xs.length+nx] && imos[ny*xs.length+nx] == 0){
						queue[qc++] = [ny,nx];
						visited[ny*xs.length+nx]=true;
					}
				}
			}
		}
		return 1;
	}
	for(int i=0;ys[i]<h;i++){
		for(int j=0;xs[j]<w;j++){
			ans += BFS(i,j);
		}
	}
	printf("%d\n",ans);
	
	}
}