import sequtils,strutils,math var C, D, Aw, Ab, Bw, Bb : int (Aw, Ab) = stdin.readline.split.map(parseInt) (Bw, Bb) = stdin.readline.split.map(parseInt) (C, D) = stdin.readline.split.map(parseInt) if C <= Ab: Ab -= C Bb += C else: C -= Ab Bb += Ab Ab = 0 Aw -= C Bw += C Aw += min(D, Bw) echo Aw