#include<bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
const int INF = INT_MAX/3;
const double EPS = 1e-14;

template<typename U, typename T>
void chmin(U &x, T y) { x = min(x, y); }

template<typename U, typename T>
void chmax(U &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;
typedef tuple<int,int,int,int> square;
typedef pair<int,int> P;

const int WMAX = 2500;
bool field[WMAX][WMAX];

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

int xmax, ymax;

int dfs(int x, int y) {
  if (field[x][y]) return 0;
  stack<P> s;
  s.push(P(x,y));
  while (!s.empty()) {
    P p = s.top(); s.pop();
    int x = p.first, y = p.second;
    if (x < 0 || xmax <= x || y < 0 || ymax <= y || field[x][y]) continue;
    field[x][y] = true;
    REP(dir,4) s.push(P(x + dx[dir], y + dy[dir]));
  }
  return 1;
}

int main() {
  int w, h, n;
  while (cin >> w >> h and w) {
    REP(x, WMAX) REP(y, WMAX) field[x][y] = false;
    cin >> n;
    vector<square> tapes;
    vector<int> xs, ys;
    xs.push_back(w);
    xs.push_back(0);
    ys.push_back(h);
    ys.push_back(0);
    REP(i, n) {
      int x_[2];
      int y_[2];
      cin >> x_[0] >> y_[0] >> x_[1] >> y_[1];
      tapes.push_back(make_tuple(x_[0], y_[0], x_[1], y_[1]));
      REP(i, 2) REP(d, 2) {
        xs.push_back(x_[i] + d);
        ys.push_back(y_[i] + d);
      }
    }
    sort(ALL(xs));
    xs.erase(unique(ALL(xs)));
    sort(ALL(ys));
    ys.erase(unique(ALL(ys)));
    REP(i, n) {
      get<0>(tapes[i]) = find(ALL(xs), get<0>(tapes[i])) - xs.begin();
      get<1>(tapes[i]) = find(ALL(ys), get<1>(tapes[i])) - ys.begin();
      get<2>(tapes[i]) = find(ALL(xs), get<2>(tapes[i])) - xs.begin();
      get<3>(tapes[i]) = find(ALL(ys), get<3>(tapes[i])) - ys.begin();
    }
    REP(i, n) 
      FOR(x, get<0>(tapes[i]), get<2>(tapes[i])) 
      FOR(y, get<1>(tapes[i]), get<3>(tapes[i])) {
        field[x][y] = true;
      }
    xmax = find(ALL(xs), w) - xs.begin(), ymax = find(ALL(ys), h) - ys.begin();
    REP(y, ymax + 1) { field[xmax][y] = true; }
    REP(x, xmax + 1) { field[x][ymax] = true; }
    int ans = 0;
    REP(x, xmax) REP(y, ymax) { ans += dfs(x, y); } 
    cout << ans << endl;
  }
  return 0;
}