#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int MAX_N = 2100;
long long con[MAX_N][MAX_N];
vector<long long> xalt, yalt;

long long merge(vector<pair<pair<long long,long long>, pair<long long,long long> > > rec) {
    memset(con, 0, sizeof(con));
    map<long long,int> xma, yma;
    xalt.clear(); yalt.clear();
    
    for (int i = 0; i < rec.size(); ++i) {
        long long xl = rec[i].first.first, xr = rec[i].second.first;
        long long yb = rec[i].first.second, yt = rec[i].second.second;
        xma[xl]++; xma[xr]++; yma[yb]++; yma[yt]++;
    }
    int nowx = 0;
    EACH(it,xma) {it->second = nowx++; xalt.PB(it->first);}
    int nowy = 0;
    EACH(it,yma) {it->second = nowy++; yalt.PB(it->first);}
    
    for (int i = 0; i < rec.size(); ++i) {
        int xl = xma[rec[i].first.first], xr = xma[rec[i].second.first];
        int yb = yma[rec[i].first.second], yt = yma[rec[i].second.second];
        for (int j = xl; j < xr; ++j) {con[j][yb]++; con[j+1][yt]--;}
        for (int j = yb; j < yt; ++j) {con[xl][j]++; con[xr][j+1]--;}
        con[xl][yb]--; con[xr][yt]++;
    }
    
    long long res = 0;
    for (int i = 0; i < nowx; ++i) {
        for (int j = 0; j < nowy; ++j) {
            con[i+1][j+1] += con[i][j];
            if (con[i][j] > 0) {
                res += (xalt[i+1]-xalt[i]) * (yalt[j+1]-yalt[j]);
            }
        }
    }
    
    return res;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n, m;
int c;

int X, Y;
bool seen[2010][2010];
int res;

void dfs(int i, int j) {
    seen[i][j] = true;
    for (int k = 0; k < 4; ++k) {
        int ni = i + dx[k], nj = j + dy[k];
        if (ni < 0 || ni >= X || nj < 0 || nj >= Y) continue;
        if (!seen[ni][nj] && con[ni][nj] == 1) 
            dfs(ni, nj);
    }
}

int main() {
    while (cin >> n >> m) {
        if (n == 0) break;
        cin >> c;
        
        vector<pair<pll, pll> > rec;
        rec.PB( MP(pll(0,0), pll(n,m)) );
        
        for (int i = 0; i < c; ++i) {
            ll x1, y1, x2, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            rec.PB( MP(pll(x1,y1), pll(x2,y2)) );
        }
        
        merge(rec);
        X = xalt.size()-1, Y = yalt.size()-1;
        
        memset(seen, 0, sizeof(seen));
        res = 0;
        for (int i = 0; i < X; ++i) {
            for (int j = 0; j < Y; ++j) {
                if (!seen[i][j] && con[i][j] == 1) {
                    dfs(i, j);
                    ++res;
                }
            }
        }
        
        cout << res << endl;
    }
    
    return 0;
}


Measured memory_bytes: 41904