A = input() B = input() CD = input() Aw,Ab = A.split() Bw,Bb = B.split() C,D = CD.split() Aw = int(Aw) Ab = int(Ab) Bw = int(Bw) Bb = int(Bb) C = int(C) D = int(D) if Ab - C < 0: Aw = Aw + (Ab - C) Bw = Bw + (C - Ab) if D >= Bw: Aw = Aw + Bw else: Aw = Aw + D print(str(Aw))