(a,b),(x,y),(c,d)=$<.map{|e|e.split.map(&:to_i)} z=[c-b,0].max p a-z+[x+z,d].min