// G++ MACRO.CPP -STD=C++17
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<ll>
#define M map<int,int>
#define S set<int>

#define pb(a) push_back(a)
#define mp make_pair


class UnionFindTwoDim{
public:
    vector<vector<P>> par;
    vector<V> rank;// parent,rank
    UnionFindTwoDim(int n,int m);
    P Find(P x);
    void Unite(P x,P y);
    bool Same(P x,P y);
};

UnionFindTwoDim::UnionFindTwoDim(int n,int m){
    rank = vector<V>(n,V(m,0));
    par = vector<vector<P>>(n,vector<P>(m));
    REP(i,n)REP(j,m)par[i][j]=mp(i,j);
}

P UnionFindTwoDim::Find(P x){
    
    return (par[x.first][x.second]==x?x:Find(par[x.first][x.second]));
}

void UnionFindTwoDim::Unite(P x,P y){
    x=Find(x);y=Find(y);//parent
    
    if(x==y)return;//end
    if(rank[x.first][x.second]<rank[y.first][y.second])par[x.first][x.second]=y;
    else{
        par[y.first][y.second]=x;
        if(rank[x.first][x.second]==rank[y.first][y.second])rank[x.first][x.second]++;
    }
}

bool UnionFindTwoDim::Same(P x,P y){
    return (Find(x)==Find(y));
}


int main(){
  auto f = [&](){
  CIN(h,w);
  if(!h&&!w)
    return false;
  CIN(n);VC2(n,a,b,c,d);
  S x_s,y_s;
  x_s.insert(0);
  y_s.insert(0);
  x_s.insert(h);
  y_s.insert(w);
  REP(i,n){
    x_s.insert(a[i]);
    y_s.insert(b[i]);
    x_s.insert(c[i]);
    y_s.insert(d[i]);
  }

  V x,y;
  for(auto it = x_s.begin();it!=x_s.end();it++)
    x.pb(*it);
  for(auto it = y_s.begin();it!=y_s.end();it++)
    y.pb(*it);

  vector<V> imos(x.size(),V(y.size(),0));

  REP(i,n){
    int x1 = distance(x.begin(),lower_bound(ALL(x),a[i]));
    int y1 = distance(y.begin(),lower_bound(ALL(y),b[i]));
    int x2 = distance(x.begin(),lower_bound(ALL(x),c[i]));
    int y2 = distance(y.begin(),lower_bound(ALL(y),d[i]));
    imos[x1][y1]++;
    imos[x2][y2]++;
    imos[x2][y1]--;
    imos[x1][y2]--;
  }
  REP(i,imos.size())
    FOR(j,1,imos[0].size())
      imos[i][j]+=imos[i][j-1];

  REP(j,imos[0].size())
    FOR(i,1,imos.size())
      imos[i][j]+=imos[i-1][j];


  imos.resize(imos.size()-1);
  REP(i,imos.size())
    imos[i].resize(imos[i].size()-1);

  /*
  REP(i,imos.size())
    VECCOUT(imos[i]);
  */

  UnionFindTwoDim uni(imos.size(),imos[0].size());
  REP(i,imos.size())
    REP(j,imos[0].size()){
      if(imos[i][j])continue;
      if(i!=imos.size()-1 && !imos[i+1][j])uni.Unite(mp(i,j),mp(i+1,j));
      if(j!=imos[0].size()-1 && !imos[i][j+1])uni.Unite(mp(i,j),mp(i,j+1));
    }
  set<P> s_;
  REP(i,imos.size())
    REP(j,imos[0].size())
      if(!imos[i][j])
        s_.insert(uni.Find(mp(i,j)));

  COUT(s_.size());

  return true;

  };

  while(f());

  return 0;
}



Measured memory_bytes: 10080