def unite(rg,i,f)
  if rg.empty?
    rg = [i..f]
  else
    s = [rg[-1].last,f].max
    a = Array.new(s){|j|
      val = 1
      if j<i || f<j
        for k in 0..rg.size-1
          inc = rg[k].include?(j)
          break if inc
        end
        val = (inc ? 1 : 0)
      end
      val
    }
    a+=[0]
    rg = []
    while true
      idx1 = a.rindex{|x| x==1}
      break if idx.nil?
      a = a[0..idx-1]
      idx2 = a.rindex{|x| x==0}
      rg = [idx2+1..idx1]+rg
      a = a[0..idx-1]
    end
  end
  rg
end

while true
  n,r = gets.split(" ").map{|s| s.to_i}
  break if (n==0 && r==0)
  
  a = Array.new(n){gets.split(" ").map{|s| s.to_i}}
  
  xrgs = [[]]
  yrgs = [[]]

  for i in 0..n-1
    x1,y1,x2,y2 = a[i]
    for y in y1..y2
      xrgs[y] = unite(xrgs[y],x1,x2) rescue xrgs[y] =[x1..x2]
    end
    for x in x1..x2
      yrgs[x] = unite(yrgs[x],y1,y2) rescue yrgs[x] =[y1..y2]
    end
  end

  puts xrgs.compact.map{|arr| arr.map{|rng| rng.last-rng.first+1}}.flatten.inject(:+)
  puts (xrgs+yrgs).compact.map{|arr| arr.size}.inject(:+)*2 if r==2
end