#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

struct Tape{
    int x1,x2,y1,y2;
};

int main(){
    iostream::sync_with_stdio(false);

    START:
    
    int w,h,n;
    cin >> w >> h;
    if(w == 0 && h == 0) return 0;
    cin >> n;
    vector<Tape> t;
    vector<int> X,Y;
    X.push_back(0); X.push_back(w);
    Y.push_back(0); Y.push_back(h);
    for(int i=0; i<n; i++){
        Tape tmp;
        cin >> tmp.x1 >> tmp.y1 >> tmp.x2 >> tmp.y2;
        t.push_back(tmp);
        X.push_back(tmp.x1); X.push_back(tmp.x2);
        Y.push_back(tmp.y1); Y.push_back(tmp.y2);
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    X.erase(unique(X.begin(), X.end()), X.end());
    Y.erase(unique(Y.begin(), Y.end()), Y.end());

    int mp[2005][2005] = {}; //0が通れないことを示す
    for(int i=1; i<X.size(); i++){//X.size()-1回のループ
        for(int j=1; j<Y.size(); j++){//Y.size()-1回のループ
            mp[i][j] = -1; //-1が未探索であることを示す
        }
    }
/*
    for(int i=Y.size(); i>=0; i--){
        for(int j=0; j<X.size()+1; j++){
            if(mp[j][i] >= 0) cout << "+";
            cout << mp[j][i] << " ";
        }
        cout << endl;
    }
    cout << endl;*/
    
    for(int i=0; i<t.size(); i++){
        int x1 = lower_bound(X.begin(), X.end(), t[i].x1) - X.begin() + 1;
        int x2 = lower_bound(X.begin(), X.end(), t[i].x2) - X.begin() + 1;
        int y1 = lower_bound(Y.begin(), Y.end(), t[i].y1) - Y.begin() + 1;
        int y2 = lower_bound(Y.begin(), Y.end(), t[i].y2) - Y.begin() + 1;
        for(int j=x1; j<x2; j++){
            for(int k=y1; k<y2; k++){
                mp[j][k] = 0;
            }
        }
    }
/*
    for(int i=Y.size(); i>=0; i--){
        for(int j=0; j<X.size()+1; j++){
            if(mp[j][i] >= 0) cout << "+";
            cout << mp[j][i] << " ";
        }
        cout << endl;
    }
    cout << endl;*/

    int tmp = 1;
    for(int i=1; i<X.size(); i++){
        for(int j=1; j<Y.size(); j++){
            if(mp[i][j] == -1){
                mp[i][j] = tmp;
                queue<pair<int,int> > que;
                que.push(make_pair(i, j));
                while(!que.empty()){
                    if(mp[que.front().first-1][que.front().second] == -1){
                        mp[que.front().first-1][que.front().second] = tmp;
                        que.push(make_pair(que.front().first-1, que.front().second));
                    }
                    if(mp[que.front().first+1][que.front().second] == -1){
                        mp[que.front().first+1][que.front().second] = tmp;
                        que.push(make_pair(que.front().first+1, que.front().second));
                    }
                    if(mp[que.front().first][que.front().second-1] == -1){
                        mp[que.front().first][que.front().second-1] = tmp;
                        que.push(make_pair(que.front().first, que.front().second-1));
                    }
                    if(mp[que.front().first][que.front().second+1] == -1){
                        mp[que.front().first][que.front().second+1] = tmp;
                        que.push(make_pair(que.front().first, que.front().second+1));
                    }
                    que.pop();
                }
                tmp++;
            }
        }
    }
/*
    for(int i=Y.size(); i>=0; i--){
        for(int j=0; j<X.size()+1; j++){
            if(mp[j][i] >= 0) cout << "+";
            cout << mp[j][i] << " ";
        }
        cout << endl;
    }
    cout << endl;*/
    
    cout << tmp-1 << endl;

    goto START;
    
    return 0;
}

/*
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);
    

    
    return 0;
}
*/


Measured memory_bytes: 18816