#include <set>
#include <iostream>
#include <cstdio>
#include <climits>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

typedef pair<int, int> Range;
typedef vector<Range> Ranges;

struct Rect{
  int ldx, ldy;
  int rux, ruy;

  Rect(){}
  Rect(int ldxx, int ldyy,
       int ruxx, int ruyy) :
    ldx(ldxx), ldy(ldyy),
    rux(ruxx), ruy(ruyy) {}
};

bool operator < (const Rect &lhs, const Rect &rhs){
  if(lhs.ldx != rhs.ldx) return lhs.ldx < rhs.ldx;
  if(lhs.rux != rhs.rux) return lhs.rux < rhs.rux;
  if(lhs.ldy != rhs.ldy) return lhs.ldy < rhs.ldy;
  return lhs.ruy < rhs.ruy;
}

typedef vector<Rect> Rects;

void addRange(Ranges &dst, Range rng){
  int idx = lower_bound(dst.begin(), dst.end(), rng) - dst.begin();

  bool f1 = false;
  bool f2 = false;

  /*
  printf("before: "); REP(i,dst.size()) printf("(%d %d) ", dst[i].first, dst[i].second); puts("");
  */

  if(idx != 0){
    if(rng.first <= dst[idx - 1].second){
      dst[idx - 1].second = max(dst[idx - 1].second, rng.second);
      f1 = true;
    }
  }

  int idx2 = idx;
  while(idx2 != (int)dst.size() && dst[idx2].second <= rng.second) idx2++;

  if(idx2 != (int)dst.size()){
    if(dst[idx2].first <= rng.second){
      dst[idx2].first  = rng.first;
      dst[idx2].second = max(dst[idx2].second, rng.second);
      f2 = true;
    }
  }

  if(f1 && f2){
    dst[idx - 1].second = dst[idx2].second;
    dst.erase(dst.begin() + idx2);
    if(idx < idx2)
      dst.erase(dst.begin() + idx, dst.begin() + idx2);
  }else{
    if(idx < idx2)
      dst.erase(dst.begin() + idx, dst.begin() + idx2);

    if(!f1 && !f2)
      dst.insert(dst.begin() + idx, rng);
  }
  /*
  printf("add (%d %d):\n", rng.first, rng.second);
  printf("after: "); REP(i,dst.size()) printf("(%d %d) ", dst[i].first, dst[i].second); puts("");
  */
}

int rangeLength(const Ranges &rngs){
  int ret = 0;
  FOR(it, rngs){
    ret += it->second - it->first;
  }
  return ret;
}

// from sorted rects
template<typename Use>
Ranges createRanges(const Rects &rects, const Use &use){
  Ranges ret;
  FOR(it, use){
    const Rect &r = rects[*it];
    addRange(ret, Range(r.ldy, r.ruy));
  }
  return ret;
}

inline void getrng(const Ranges &rngs, int &sx, int &ex, int n){
  sx = n == (int)rngs.size() ? INT_MAX : rngs[n].first;
  ex = n == (int)rngs.size() ? INT_MAX : rngs[n].second;
}

int diffRange(const Ranges &r1, const Ranges &r2){
  int p1 = 0;
  int p2 = 0;
  int ret = 0;

  int sx1, ex1, sx2, ex2;
  getrng(r1, sx1, ex1, p1);
  getrng(r2, sx2, ex2, p2);

  while(p1 != (int)r1.size() || p2 != (int)r2.size()){
    // printf(" (%d %d) (%d %d) : %d\n", sx1, ex1, sx2, ex2, ret);
    if(ex1 <= sx2){
      ret += ex1 - sx1;
      getrng(r1, sx1, ex1, ++p1);
    }else if(ex2 <= sx1){
      ret += ex2 - sx2;
      getrng(r2, sx2, ex2, ++p2);
    }else{
      if(ex1 < ex2){
        ret += abs(sx2 - sx1);
        sx2 = ex1;
        getrng(r1, sx1, ex1, ++p1);
      }else{
        ret += abs(sx1 - sx2);
        sx1 = ex2;
        getrng(r2, sx2, ex2, ++p2);
      }
    }
  }

  return ret;
}

enum Event{
  ADD = 0,
  DEL = 1
};

// must be sorted
pair<int, int> calc(const Rects &rects){
  const int n = rects.size();
  vector<pair<int, pair<int, int> > > events(2 * n);

  int minx = INT_MAX;
  int maxx = 0;

  REP(i,n){
    events[2 * i].first = rects[i].ldx;
    events[2 * i].second.first  = i;
    events[2 * i].second.second = ADD;
    minx = min(minx, rects[i].ldx);

    events[2 * i + 1].first = rects[i].rux;
    events[2 * i + 1].second.first  = i;
    events[2 * i + 1].second.second = DEL;
    maxx = max(maxx, rects[i].rux);
  }

  sort(events.begin(), events.end());

  int ptr = 0;

  int men = 0;
  int shu = 0;
  Ranges rngs;
  int len = 0;
  int px  = 0;
  set<int> use;

  while(ptr != 2 * n){
    int xx = events[ptr].first;

    // update ans
    men += len * (xx - px);
    shu += 2 * rngs.size() * (xx - px);

    // update others
    px = xx;

    while(ptr != 2 * n && events[ptr].first == xx){
      int id = events[ptr].second.first;
      int tp = events[ptr].second.second;

      if(tp == ADD) use.insert(id);
      else use.erase(id);

      ptr++;
    }

    Ranges rtmp = createRanges(rects, use);
    // printf(" diffRange = %d\n", diffRange(rtmp, rngs));
    shu += diffRange(rtmp, rngs);
    rngs.swap(rtmp);
    len = rangeLength(rngs);

    /*
    printf("x = %d: (%d, %d) len = %d\n", px, men, shu, len);
    REP(i,rngs.size()){
      printf(" [%d, %d]\n", rngs[i].first, rngs[i].second);
    }
    */
  }

  return make_pair(men, shu);
}

int main(){
  while(true){
    const int n = getInt();
    const int r = getInt();

    if(n + r == 0) break;

    Rects rects(n);

    REP(i,n){
      rects[i].ldx = getInt();
      rects[i].ldy = getInt();
      rects[i].rux = getInt();
      rects[i].ruy = getInt();
    }

    sort(rects.begin(), rects.end());
    const pair<int, int> ret = calc(rects);

    printf("%d\n", ret.first);
    if(r == 2)
      printf("%d\n", ret.second);
  }

  return 0;
}

Measured memory_bytes: 1452