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