Aw,Ab = map(int,input().split()) Bw,Bb = map(int,input().split()) c,d = map(int,input().split()) if Ab >= c: Ab-=c Bb+=c else: Ab, Bb, Aw, Bw = 0, Bb + Ab, Aw - (c - Ab), Bw + (c - Ab) #print(Aw,Ab,Bw,Bb) if Bw >= d: Bw -= d Aw += d else: Bw ,Aw, Bb, Ab = 0, Aw + Bw, Bb - (d-Bw), Ab + (d-Bw) #print(Aw,Ab,Bw,Bb) print(Aw)