import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int n, r;
    while (readf("%d %d\n", &n, &r), n || r) {
        int X, Y;
        bool[] ya = new bool[10001],
               yb = new bool[10001],
               xa = new bool[10001],
               xb = new bool[10001];
        int[][] ys1 = new int[][10001],
                ys2 = new int[][10001],
                xs1 = new int[][10001],
                xs2 = new int[][10001];
        foreach (i; 0 .. n) {
            int x1, y1, x2, y2; readf("%d %d %d %d\n", &x1, &y1, &x2, &y2);
            xa[x1] = ya[y1] = true;
            xb[x2] = yb[y2] = true;
            xs1[y1] ~= [x1, x2];
            xs2[y2] ~= [x1, x2];
            ys1[x1] ~= [y1, y2];
            ys2[x2] ~= [y1, y2];
            X = max(X, x2);
            Y = max(Y, y2);
        }
        int area = 0;
        int[] d = new int[10001];
        foreach (i; 0 .. Y + 1) {
            if (ya[i]) {
                for (int j = 0; j < xs1[i].length; j += 2) {
                    d[xs1[i][j]]++;
                    d[xs1[i][j + 1]]--;
                }
            } 
            if (yb[i]) {
                for (int j = 0; j < xs2[i].length; j += 2) {
                    d[xs2[i][j]]--;
                    d[xs2[i][j + 1]]++;
                }
            }
            int c = 0;
            foreach (j; 0 .. X + 1) {
                if (d[j]) {
                    c += d[j];
                }
                if (c) area++;
            }
        }
        area.writeln;
        if (r == 2) {
            int cir = 0;
            int c = 0;
            d[] = 0;
            foreach (i; 0 .. Y + 1) {
                if (ya[i]) {
                    for (int j = 0; j < xs1[i].length; j += 2) {
                        d[xs1[i][j]]++;
                        d[xs1[i][j + 1]]--;
                    }
                }
                if (yb[i]) {
                    for (int j = 0; j < xs2[i].length; j += 2) {
                        d[xs2[i][j]]--;
                        d[xs2[i][j + 1]]++;
                    }
                }
                foreach (j; 0 .. X + 1) {
                    if (d[j]) {
                        if (c == 0) cir++;
                        c += d[j];
                        if (c == 0) cir++;
                    }
                }
            }
            d[] = 0;
            foreach (i; 0 .. X + 1) {
                if (xa[i]) {
                    for (int j = 0; j < ys1[i].length; j += 2) {
                        d[ys1[i][j]]++;
                        d[ys1[i][j + 1]]--;
                    }
                } 
                if (xb[i]) {
                    for (int j = 0; j < ys2[i].length; j += 2) {
                        d[ys2[i][j]]--;
                        d[ys2[i][j + 1]]++;
                    }
                }
                foreach (j; 0 .. Y + 1) {
                    if (d[j]) {
                        if (c == 0) cir++;
                        c += d[j];
                        if (c == 0) cir++;
                    }
                }
            }
            cir.writeln;
        }
    }
}

Measured memory_bytes: 7508