#include <stdio.h>
#include <vector>
#define MAX (10000+2)
using namespace std;
int main(){
    int n, r, x1, x2, y1, y2;
    while(true){
        scanf("%d %d", &n, &r);
        if(n==0 && r==0) break;
        int plane[2][MAX]={0};
        vector<vector<pair<int, int> > > sheets(MAX);
        for(int i=0; i<n; i++){
            scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
            sheets[x1+1].push_back(make_pair(y1+1,+1));
            sheets[x1+1].push_back(make_pair(y2+1,-1));
            sheets[x2+1].push_back(make_pair(y1+1,-1));
            sheets[x2+1].push_back(make_pair(y2+1,+1));
        }
        if(r==2){
            int area=0, length=0;
            for(int x=1; x<MAX; x++){
                for(int i=0; i<MAX; i++){
                    plane[x%2][i]=0;
                }
                for(vector<pair<int, int> >::iterator sheet=sheets[x].begin(); sheet!=sheets[x].end(); sheet++){
                    plane[x%2][(*sheet).first]+=(*sheet).second;
                }
                for(int y=1; y<MAX; y++){
                    plane[x%2][y]+=plane[x%2][y-1];
                }
                for(int y=1; y<MAX; y++){
                    plane[x%2][y]+=plane[(x+1)%2][y];
                    area+=plane[x%2][y]>0 ? 1 : 0;
                    length+=(plane[x%2][y-1]>0)!=(plane[x%2][y]>0) ? 1 : 0;
                    length+=(plane[x%2][y]>0)!=(plane[(x+1)%2][y]>0) ? 1 : 0;
                }
            }
            printf("%d\n%d\n", area, length);
        }else{
            int area=0;
            for(int x=1; x<MAX; x++){
                for(int i=0; i<MAX; i++){
                    plane[x%2][i]=0;
                }
                for(vector<pair<int, int> >::iterator sheet=sheets[x].begin(); sheet!=sheets[x].end(); sheet++){
                    plane[x%2][(*sheet).first]+=(*sheet).second;
                }
                for(int y=1; y<MAX; y++){
                    plane[x%2][y]+=plane[x%2][y-1];
                }
                for(int y=1; y<MAX; y++){
                    plane[x%2][y]+=plane[(x+1)%2][y];
                    area+=plane[x%2][y]>0 ? 1 : 0;
                }
            }
            printf("%d\n", area);
        }
    }
    return 0;
}
