#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAX_N = 8001;

// üÍ
int W,H,N;
int X1[MAX_N];
int X2[MAX_N];
int Y1[MAX_N];
int Y2[MAX_N];

int compress(int *x1,int *x2,int w){
  vector<int> xs;
  for(int i = 0; i < N; i++){
    for(int d = -1; d <= 1; d++){
      int tx1 = x1[i] + d;
      int tx2 = x2[i] + d;
      if(0 <= tx1 && tx1 <= w)xs.push_back(tx1);
      if(0 <= tx2 && tx2 <= w)xs.push_back(tx2);
    }
  }
  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());
  for(int i = 0; i < N; i++){
    x1[i] = find(xs.begin(),xs.end(),x1[i]) - xs.begin();
    x2[i] = find(xs.begin(),xs.end(),x2[i]) - xs.begin();
  }
  return xs.size();
}

bool fld[MAX_N][MAX_N];
const int dy[]={-1,0,0,1};
const int dx[]={0,-1,1,0};

typedef pair<int,int> pii;

pair<pii,pii> Points[MAX_N];

int main(){
  while(cin>>W>>H&&(W|H)){
    cin>>N;
    W++;H++;
    for(int i=0;i<N;i++){
      int minx,miny,maxx,maxy;
      cin>>minx>>miny>>maxx>>maxy;
      maxx--;maxy--;
      minx++;miny++;maxx++;maxy++;
      Points[i].first=pii(miny,minx);
      Points[i].second=pii(maxy,maxx);
    }
    sort(Points,Points+N);
    for(int i=0;i<=N;i++){
      int minx,miny,maxx,maxy;
      if(i!=N){
	minx=Points[i].first.second;
	miny=Points[i].first.first;
	maxx=Points[i].second.second;
	maxy=Points[i].second.first;
      }
      else{
	minx=0;miny=0;
	maxx=W;maxy=H;
      }
      X1[i*4]=minx;X2[i*4]=maxx;
      Y1[i*4]=miny;Y2[i*4]=miny;
      X1[i*4+1]=maxx;X2[i*4+1]=maxx;
      Y1[i*4+1]=miny;Y2[i*4+1]=maxy;
      X1[i*4+2]=maxx;X2[i*4+2]=minx;
      Y1[i*4+2]=maxy;Y2[i*4+2]=maxy;
      X1[i*4+3]=minx;X2[i*4+3]=minx;
      Y1[i*4+3]=maxy;Y2[i*4+3]=miny;
    }
    N++;
    N*=4;
    W=compress(X1,X2,W);
    H=compress(Y1,Y2,H);
    N/=4;
    memset(fld,0,sizeof(fld));
    queue<pii> q;
    for(int i=0;i<N;i++){
      int minx=X1[i*4];
      int maxx=X2[i*4];
      int miny=Y1[i*4+1];
      int maxy=Y2[i*4+1];
      for(int j=X1[i*4];j<=X2[i*4];j++){
	fld[Y1[i*4]][j]=true;
	int ny=miny+1;
	int nx=j;
	if(i!=N-1&&ny>miny&&nx>minx&&ny<maxy&&nx<maxx
	   &&!fld[ny][nx]){
	  q.push(pii(ny,nx));
	  fld[ny][nx]=true;
	}
      }
      for(int j=X2[i*4+2];j<=X1[i*4+2];j++){
	fld[Y1[i*4+2]][j]=true;
	int ny=maxy-1;
	int nx=j;
	if(i!=N-1&&ny>miny&&nx>minx&&ny<maxy&&nx<maxx
	   &&!fld[ny][nx]){
	  q.push(pii(ny,nx));
	  fld[ny][nx]=true;
	}
      }
      for(int j=Y1[i*4+1];j<=Y2[i*4+1];j++){
	fld[j][X1[i*4+1]]=true;
	int ny=j;
	int nx=maxx-1;
	if(i!=N-1&&ny>miny&&nx>minx&&ny<maxy&&nx<maxx
	   &&!fld[ny][nx]){
	  q.push(pii(ny,nx));
	  fld[ny][nx]=true;
	}
      }
      for(int j=Y2[i*4+3];j<=Y1[i*4+3];j++){
	fld[j][X1[i*4+3]]=true;
	int ny=j;
	int nx=minx+1;
	if(i!=N-1&&ny>miny&&nx>minx&&ny<maxy&&nx<maxx
	   &&!fld[ny][nx]){
	  q.push(pii(ny,nx));
	  fld[ny][nx]=true;
	}
      }
      while(q.size()){
	pii p=q.front();q.pop();
	for(int i=0;i<4;i++){
	  int ny=p.first+dy[i];
	  int nx=p.second+dx[i];
	  if(ny>=0&&nx>=0&&ny<H&&nx<W&&!fld[ny][nx]){
	    fld[ny][nx]=true;
	    q.push(pii(ny,nx));
	  }
	}
      }
    }
    int res=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if(fld[i][j])continue;
	q.push(pii(i,j));
	fld[i][j]=true;
	while(q.size()){
	  pii p=q.front();q.pop();
	  for(int k=0;k<4;k++){
	    int ny=p.first+dy[k];
	    int nx=p.second+dx[k];
	    if(ny>=0&&nx>=0&&ny<H&&nx<W&&!fld[ny][nx]){
	      q.push(pii(ny,nx));
	      fld[ny][nx]=true;
	    }
	  }
	}
	res++;
      }
    }
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 0