#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pi acos(-1)
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep(i,x,n) for(int i=x;i<n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define y1 Y1
using namespace std;
typedef pair<int,int>P;
const int MAXN=2010;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int x1[MAXN], x2[MAXN];
int y1[MAXN], y2[MAXN];
int Hash(int a[], int b[], int w, int n)
{
	vector<int> h;
	for(int i = 0; i < n; i++)
	h.pb(a[i]), h.pb(b[i]);
	h.pb(0);
	h.pb(w);
	sort(h.begin(), h.end());
	h.erase(unique(h.begin(),h.end()), h.end());
	for(int i = 0; i < n; i++)
	{
		a[i] = lower_bound(h.begin(), h.end(), a[i]) - h.begin();
		b[i] = lower_bound(h.begin(), h.end(), b[i]) - h.begin();
	}
	return h.size() - 1;
}
int book[MAXN][MAXN];
int W, H;
int go[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
void dfs(int r, int c)
{
	if(r < 0 || c < 0 || r > H || c > W || book[r][c]) return ;
	book[r][c] = 1;
	for(int i = 0; i < 4; i++)
	dfs(r + go[i][0], c + go[i][1]);
}
int main()
{
	
	while(cin >> W >> H && W + H)
	{
		memset(book, 0, sizeof(book));
		int n, ans = 0;
		cin >> n;
		for(int i = 0; i < n; i++)
		scanf("%d %d %d %d", &x1[i], &y1[i], &x2[i], &y2[i]);
		W = Hash(x1, x2, W, n);
		H = Hash(y1, y2, H, n);
		//cout << W << " " << H << endl;
		//for(int i = 0; i < n; i++)
		//cout << x1[i] << " ";
		for(int i = 0; i < n; i++)
		{
			book[y1[i]][x2[i]]++;
			book[y1[i]][x1[i]]--;
			book[y2[i]][x1[i]]++;
			book[y2[i]][x2[i]]--;
		}
		for(int i = 0; i < H; i++)
		for(int j = 1; j < W; j++)
		book[i][j] += book[i][j - 1];
		for(int i = 1; i < H; i++)
		for(int j = 0; j < W; j++)
		book[i][j] += book[i - 1][j];
		//for(int i = 0; i <= H; i++)
		//for(int j = 1; j <= W; j++)
		//printf("%d%c", book[i][j], " \n"[j == W]);
		for(int i = 0; i < H; i++)
		for(int j = 0; j < W; j++)
		{
			if(book[i][j])continue;
			dfs(i, j);
			ans++;
		}
		cout << ans << endl;
	}
 	return 0;
}