main = do
	[aw, ab, bw, bb, c, d] <- getContents >>= return . concat . map (map (read::String->Int) . words) . lines
	print $ 
		if c < ab
			then if d < bw
				then aw + d
				else aw + bw
			else if d < bw + c - ab
				then aw - (c - ab) + d
				else aw + bw