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

#define X first
#define Y second
#define all(c) (c).begin(), (c).end()

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

int compress ( VI &va, VI &vb, int wh )
{
	int n = va.size();
	VI vc;
	for (int i = 0; i < n; ++i) {
		for (int d = -1; d <= 1; ++d) {
			int ta = va[i] + d, tb = vb[i] + d;
			if (0 <= ta && ta < wh) { vc.push_back(ta); }
			if (0 <= tb && tb < wh) { vc.push_back(tb); }
		}
	}
	sort(all(vc));
	vc.erase(unique(all(vc)), vc.end());
	for (int i = 0; i < n; ++i) {
		va[i] = find(all(vc), va[i]) - vc.begin();
		vb[i] = find(all(vc), vb[i]) - vc.begin();
	}
	return vc.size();
}

int main ( void )
{
	int dx[] = { 0, 0, -1, 1 }, dy[] = { -1, 1, 0, 0 };
	int w, h, n;
	while (cin >> w >> h, w|h) {
		cin >> n;
		VI xa(n), xb(n), ya(n), yb(n);
		for (int i = 0; i < n; ++i) {
			cin >> xa[i] >> ya[i] >> xb[i] >> yb[i];
		}
		w = compress(xa, xb, w);
		h = compress(ya, yb, h);

		vector<vector<bool> > fld(h, vector<bool>(w, false));
		for (int i = 0; i < n; ++i) {
			for (int y = ya[i]; y < yb[i]; ++y) {
				for (int x = xa[i]; x < xb[i]; ++x) {
					fld[y][x] = true;
				}
			}
		}

		int ans = 0;
		for (int y = 0; y < h; ++y) {
			for (int x = 0; x < w; ++x) {
				if (fld[y][x]) { continue; }
				++ans;

				queue<PII> que;
				que.push(PII(x, y));
				while (!que.empty()) {
					PII p = que.front(); que.pop();

					for (int d = 0; d < 4; ++d) {
						PII t(p.X + dx[d], p.Y + dy[d]);
						if (t.X < 0 || t.X >= w || t.Y < 0 || t.Y >= h) { continue; }
						if (fld[t.Y][t.X]) { continue; }
						que.push(t);
						fld[t.Y][t.X] = true;
					}
				}
			}
		}

		cout << ans << endl;
	}
	return 0;
}