while true
  n,r = gets.split(" ").map{|s| s.to_i}
  break if (n==0 && r==0)
  
  x1s,y1s,x2s,y2s = [],[],[],[]

  for i in 0..n-1
    x1s[i],y1s[i],x2s[i],y2s[i] = gets.split(" ").map{|s| s.to_i}
  end
  
  xmin = x1s.min
  ymin = y1s.min
  xmax = x2s.max
  ymax = y2s.max

  f = Array.new(ymax){|y| f = "0"*xmax
           unless x<xmin || xmax<x || y<ymin || ymax<y
             for i in 0..n-1
               inc = (y1s[i]<=y && y<y2s[i] && x1s[i]<=x && x<x2s[i])
               break if inc
             end
             f[x] = "1" if inc
           end
        }
      }

  puts f.map{|s| (s.split("0")-[""]).map{|str| str.size}}.inject(:+)
  puts (f+f.transpose).map{|arr| (arr.to_s.split("0")-[""]).size}.inject(:+)*2 if r==2
end