A_w, A_b = map(int, input().split()) B_w, B_b = map(int, input().split()) C, D = map(int, input().split()) a = 0 if C > A_b: a = C - A_b A_w -= a b = 0 if D > B_w + a: b = B_w + A_w + a else: b = D + A_w print(b)