#include <bits/stdc++.h>

#define LL long long
#define VI vector<int>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

const std::string YES = "YES";
const std::string Yes = "Yes";
const std::string NO = "NO";
const std::string No = "No";

bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }

// 4近傍（右, 下, 左, 上）
const std::vector<int> dy = { 0, -1, 0, 1 };
const std::vector<int> dx = { 1, 0, -1, 0 };

using namespace std;

class CoordinateCompression {
public:
    unordered_map<long long, int> zip;    // 元の値 ->　圧縮した値
    unordered_map<int, long long> unzip;  // 圧縮した値 -> 元の値

    CoordinateCompression(const vector<long long> &v) {
        set<long long> s(v.begin(), v.end());

        int no = 0;
        for (long long x : s) {
            zip[x] = no;
            unzip[no] = x;
            ++no;
        }
    }
};

void dfs(int y, int x, vector<vector<int>> &field) {
    field[y][x] = 1;
    FOR(i, 0, 4) {
        int ny = dy[i] + y;
        int nx = dx[i] + x;

        if (inside(ny, nx, field.size(), field[0].size())) {
            if (field[ny][nx] == 0) {
                dfs(ny, nx, field);
            }
        }
    }
}


int solve(LL W, LL H, LL N, const vector<LL> &X1, const vector<LL> &Y1, const vector<LL> &X2, const vector<LL> &Y2) {

    vector<LL> _x(X1);
    _x.insert(_x.end(), ALL(X2));
    _x.emplace_back(0);
    _x.emplace_back(W);

    vector<LL> _y(Y1);
    _y.insert(_y.end(), ALL(Y2));
    _y.emplace_back(0);
    _y.emplace_back(H);

    CoordinateCompression x(_x);
    CoordinateCompression y(_y);

    int c_w = x.zip[W];
    int c_h = y.zip[H];

    vector<vector<int>> field(c_h, vector<int>(c_w, 0));

    FOR(i, 0, N) {
        int x1 = x.zip[X1[i]];
        int y1 = y.zip[Y1[i]];
        int x2 = x.zip[X2[i]];
        int y2 = y.zip[Y2[i]];

        FOR(i, c_h - y2, c_h - y1) {
            FOR(j, x1, x2) {
                field[i][j] = 1;
            }
        }
    }

//    FOR(i, 0, field.size()) {
//        FOR(j, 0, field[0].size()) {
//            cout << (field[i][j] ? "■" : "□");
//        }
//        cout << endl;
//    }

    int ans = 0;
    FOR(i, 0, field.size()) {
        FOR(j, 0, field[0].size()) {
            if (field[i][j] == 0) {
                ans += 1;
                dfs(i, j, field);
            }
        }
    }

    cout << ans << endl;
}


int main() {
    while (true) {
        LL w, h, n;
        cin >> w >> h;

        if (w == 0 and h == 0) {
            break;
        }

        cin >> n;
        vector<LL> x1(n), y1(n), x2(n), y2(n);
        FOR(i, 0, n) {
            cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        }

        solve(w, h, n, x1, y1, x2, y2);
    }
    return 0;
}


Measured memory_bytes: 10340