Aw,Ab = map(int,raw_input().split()) Bw,Bb = map(int,raw_input().split()) C,D = map(int,raw_input().split()) t = max(0,C-Ab) print (Aw-t)+min(t+Bw,D)