aw,ab,bw,bb,c,d=STDIN.read.split.map(&:to_i) t=[c-ab, 0].max puts aw-t+[bw+t, d].min