def unite(rg,i,f)
  if rg.nil? || rg.empty?
    rg = [i..f]
  else
    a = []
    for k in i..f
      a[k] = 0
    end
    for j in 0..rg.size-1
      for k in rg[j]
        a[k] = 0
      end
    end
    rg = []
    while true
      idx1 = a.rindex{|x| x==0}
      break if idx1.nil?
      a = a[0..idx1-1]
      idx2 = a.rindex{|x| x.nil?}
      idx2.nil? ? (rg=[0..idx1]+rg ;break) : rg = [idx2+1..idx1]+rg
      a = a[0..idx2-1]
    end
  end
  rg
end

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

  for i in 0..n-1
    x1,y1,x2,y2 = gets.split(" ").map{|s| s.to_i}
    for y in y1..y2-1
      xrgs[y] = unite(xrgs[y],x1,x2-1)
    end
    for x in x1..x2-1
      yrgs[x] = unite(yrgs[x],y1,y2-1)
    end
  end

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