# 入力の読み込み A_w, A_b = map(int, input().split()) B_w, B_b = map(int, input().split()) C, D = map(int, input().split()) # 取り得る白石の数の最小値と最大値を計算 x_min = max(0, C - A_b) x_max = min(C, A_w) # 各ケースを判定 case1 = (B_w + x_max) <= D case2 = (B_w + x_min) >= D if case1: max_white = A_w + B_w elif case2: max_white = (A_w - x_min) + D else: max_white = A_w + B_w print(max_white)