Aw, Ab = map(int, raw_input().split()) Bw, Bb = map(int, raw_input().split()) C, D = map(int, raw_input().split()) if C <= Ab: Ab = Ab - C Bb = Bb + C else: Aw = Aw - (C - Ab) Bw = Bw + (C - Ab) Bb = Bb + Ab Ab = Ab - Ab #print Aw, Ab, Bw, Bb if D <= Bw: Bw = Bw - D Aw = Aw + D else: Bb = Bb - (D - Bw) Ab = Ab + (D - Bw) Bw = Bw - Bw Aw = Aw + Bw #print Aw, Ab, Bw, Bb print Aw