aw, ab = map(int, input().split()) bw, bb = map(int, input().split()) c, d = map(int, input().split()) if ab < c: aw -= c-ab bw += c-ab aw += min(bw, d) print(aw)