#include <cstdio>
#include <vector>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

struct R{
	R(){}
	R(int a, int b, int c, int d): a(a), b(b), c(c), d(d){}

	int a, b, c, d;
};

int n, r;
vector<R> v;

R rect_intersect(const R& x, const R& y){
	return R(max(x.a, y.a), max(x.b, y.b), min(x.c, y.c), min(x.d, y.d));
}

bool rect_empty(const R& x){
	return x.a >= x.c || x.b >= x.d;
}

bool rect_cmp(const R& x, const R& y){
	return x.a == y.a && x.b == y.b && x.c == y.c && x.d == y.d;
}

int rect_area(const R& x){
	return (x.c - x.a) * (x.d - x.b);
}

int rect_around(const R& x){
	return ((x.c - x.a) + (x.d - x.b)) * 2;
}

int area(const vector<R>& v, const R& x){
	rep(i, v.size()){
		if(rect_cmp(v[i], x)){
			return rect_area(x);
		}
	}

	int p = (x.a + x.c) / 2;
	int q = (x.b + x.d) / 2;

	R y[4] = {
		R(x.a, x.b, p, q),
		R(x.a, q, p, x.d),
		R(p, x.b, x.c, q),
		R(p, q, x.c, x.d)
	};
	vector<R> a[4];
	rep(i, v.size()){
		rep(j, 4){
			R t = rect_intersect(v[i], y[j]);
			if(!rect_empty(t)){
				a[j].push_back(t);
			}
		}
	}

	int r = 0;
	rep(j, 4){
		if(!a[j].empty()){
			r += area(a[j], y[j]);
		}
	}

	return r;
}

template<typename U, typename V> void copy_n(U it1, int n, V it2){
	rep(i, n){
		*(it2 + i) = *(it1 + i);
	}
}

pair<int, vector<int> > around(const vector<R>& v, const R& x){
	rep(i, v.size()){
		if(rect_cmp(v[i], x)){
			int u = rect_around(x);

			// printf("(%d %d %d %d) %d\n", x.a, x.b , x.c ,x.d ,u);

			return make_pair(u, vector<int>(u, 1));
		}
	}

	int p = (x.a + x.c) / 2;
	int q = (x.b + x.d) / 2;

	R y[4] = {
		R(x.a, x.b, p, q),
		R(x.a, q, p, x.d),
		R(p, x.b, x.c, q),
		R(p, q, x.c, x.d)
	};
	vector<R> a[4];
	rep(i, v.size()){
		rep(j, 4){
			R t = rect_intersect(v[i], y[j]);
			if(!rect_empty(t)){
				a[j].push_back(t);
			}
		}
	}

	int r = 0;
	int sx = x.c - x.a;
	int sy = x.d - x.b;
	vector<int> m1(sx, 0);
	vector<int> m2(sx, 0);
	vector<int> m3(sy, 0);
	vector<int> m4(sy, 0);
	vector<int> rv(rect_around(x));

	int _a = x.a, b = x.b, c = x.c, d = x.d;
	int pc = c- p;
	int ap = p - _a;
	int bq = q -b;
	int qd = d - q;

	rep(j, 4){
		if(!a[j].empty()){
			
			pair<int, vector<int> > _q = around(a[j], y[j]);
			r += _q.first;
			vector<int>::iterator qv = _q.second.begin();
			if(j == 0){
				copy_n(qv + ap, bq, m3.begin());
				copy_n(qv + ap + bq, ap, m1.begin() + pc);
				copy_n(qv, p - x.a, rv.begin());
				copy_n(qv + ap + ap + bq, bq, rv.begin() + sx + sx + sy + qd);
			}
			else if(j == 1){
				copy_n(qv, ap, m2.begin());
				copy_n(qv + ap, qd, m3.begin() + bq);
				copy_n(qv + p - x.a + x.d - q, ap + qd, rv.begin() + sx + sy + x.c - p);
			}
			else if(j == 2){
				copy_n(qv + pc + bq, pc, m1.begin());
				copy_n(qv + pc + bq + pc, bq, m4.begin() + qd);
				copy_n(qv, pc + bq, rv.begin() + ap);
			}
			else{
				copy_n(qv, pc, m2.begin() + ap);
				copy_n(qv + qd + pc + pc , qd, m4.begin());
				copy_n(qv + pc, pc + qd, rv.begin() + sx + bq);
			}
		}
	}

	/*if(ap == 0){
		copy_n(m4.begin(), sy, rv.begin() + sx + sy + sx);

	}
	if(bq == 0){
		copy_n(m1.begin(), sx, rv.begin() + sx + sy);
	}*/

	/*
	if(sx < 10){
		rep(i, sx){
			printf("%d ", m1[i]);
		}
		printf("\n");
		rep(i, sx){
			printf("%d ", m2[i]);
		}
		printf("\n");

		rep(i, sy){
			printf("%d ", m3[i]);
		}
		printf("\n");
		rep(i, sy){
			printf("%d ", m4[i]);
		}
		printf("\n");
	}
	*/

	rep(i, sx){
		if(m1[i] && m2[sx - i - 1]){
			r -= 2;
		}
	}
	rep(i, sy){
		if(m3[i] && m4[sy - i - 1]){
			r -= 2;
		}
	}

	/*printf("(%d %d %d %d) %d\n", x.a, x.b , x.c ,x.d ,r);
	if(rv.size() < 20){
		rep(i, rv.size()){
			printf("%d ", rv[i]);
		}
		printf("\n");
	}*/

	return make_pair(r, rv);
}

int main(){
	while(1){
		scanf("%d%d", &n, &r);
		if(n == 0){
			break;
		}
		rep(i, n){
			R p;
			scanf("%d%d%d%d", &p.a, &p.b, &p.c, &p.d);
			v.push_back(p);
		}

		printf("%d\n", area(v, R(0, 0, 1 << 14, 1 << 14)));
		if(r == 2){
			printf("%d\n", around(v, R(0, 0, 1 << 14, 1 << 14)).first);
		}
		v.clear();
	}
	return 0;
}

Measured memory_bytes: 3184