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}}.transpose
  
  xmax,ymax = a[2].max,a[3].max

  f = "0"*(xmax*ymax)
  
  for i in 0..n-1
    for y in a[1][i]..a[3][i]-1
      for x in a[0][i]..a[2][i]-1
        f[y*ymax+x] = "1"
      end
    end
  end

  puts xmax
  puts ymax if r==2
end