Aw,Ab = map(int, input().split()) Bw,Bb = map(int, input().split()) C,D = map(int, input().split()) Aw -= C - min(Ab, C) Bw += C - min(Ab, C) print(Aw + min(Bw, D))