#coding:utf-8 Aw,Ab=map(int,raw_input().split()) Bw,Bb=map(int,raw_input().split()) C,D=map(int,raw_input().split()) if Ab: if 0 <= (Ab-C): Bb+=C if 0 <= (Bw-D): Aw+=D else: Aw+=Bw else: Bw+=(C-Ab) Bb+=Ab Aw-=(C-Ab) if 0 <= (Bw-D): Aw+=D else: Aw+=Bw else: Bw+=C Aw-=C if 0 <= (Bw-D): Aw+=D else: Aw+=Bw print Aw