def main(): Aw, Ab = map(int, input().split()) Bw, Bb = map(int, input().split()) C, D = map(int, input().split()) if Aw < C: Bw += Aw Aw = 0 else: Bw += C Aw -= C if Bw < D: print(Aw + Bw) else: print(Aw + D) if __name__ == '__main__': main()