aw, ab = map(int, input().split()) bw, bb = map(int, input().split()) C, D = map(int, input().split()) # a -> b で、C 個移す b = min(C, ab) w = C-b if b < C else 0 ab -= b aw -= w bb += b bw += w # b -> で、D 個移す w = min(D, bw) b = D-w if w < D else 0 aw += w ab += b print(aw)