A_w, A_b = map(int, input().split()) B_w, B_b = map(int, input().split()) C, D = map(int, input().split()) x = A_w - max(0,C - A_b) B_w += max(0,C - A_b) x += min(D, B_w) print(x)