#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > Pi;

int w, h, n, x1[1000], yy1[1000], x2[1000], y2[1000];
bool mas[2200][2200];

int main(){

  while(cin >> w >> h, w){
    fill_n( *mas, 2200 * 2200, false);

    cin >> n;
    vector< int > numx, numy;
    for(int i = 0; i < n; i++){
      cin >> x1[i] >> yy1[i] >> x2[i] >> y2[i];
      for(int j = -1; j <= 1; j++){
        if(x1[i] + j >= 0 && x1[i] + j < w) numx.push_back(x1[i] + j);
        if(x2[i] + j >= 0 && x2[i] + j < w) numx.push_back(x2[i] + j);
        if(yy1[i] + j >= 0 && yy1[i] + j < h) numy.push_back(yy1[i] + j);
        if(y2[i] + j >= 0 && y2[i] + j < h) numy.push_back(y2[i] + j);
      }
    }
    sort( numx.begin(), numx.end());
    sort( numy.begin(), numy.end());
    numx.erase( unique(numx.begin(), numx.end()), numx.end());
    numy.erase( unique(numy.begin(), numy.end()), numy.end());
  

    for(int i = 0; i < n; i++){
      int xx1 = lower_bound( numx.begin(), numx.end(), x1[i]) - numx.begin();
      int xx2 = lower_bound( numx.begin(), numx.end(), x2[i]) - numx.begin();
      int yyy1 = lower_bound( numy.begin(), numy.end(), yy1[i]) - numy.begin();
      int yy2 = lower_bound( numy.begin(), numy.end(), y2[i]) - numy.begin();
      for(int j = yyy1; j < yy2; j++){
        for(int k = xx1; k < xx2; k++){
          mas[j][k] = true;
        }
      }    
    }

    int ret = 0;
    const static signed dy[] = { 1, 0, -1, 0}, dx[] = { 0, 1, 0, -1};
    queue< Pi > que;
    for(int i = 0; i < numy.size(); i++){
      for(int j = 0; j < numx.size(); j++){
        if(mas[i][j]++) continue;
        ret++;
        que.push(make_pair( i, j));
        while(!que.empty()){
          Pi p = que.front(); que.pop();
          for(int i = 0; i < 4; i++){
            int ny = p.first + dy[i], nx = p.second + dx[i];
            if(ny < 0 || ny >= numy.size() || nx < 0 || nx >= numx.size()) continue;
            if(mas[ny][nx]++) continue;
            que.push(make_pair( ny, nx));
          }
        }
      }
    }
    cout << ret << endl;
  }
}