main = getContents >>= print . goishi . map read . words goishi [aw,ab,bw,bb,c,d] = aw - (min aw (c-ab)) + (min (bw + (min aw (c-ab))) d)