Aw, Ab = map(int, input().split()) Bw, Bb = map(int, input().split()) C, D = map(int, input().split()) AtoB_w = max(0, min(C - Ab, Aw)) Bw += AtoB_w Aw -= AtoB_w Aw += max(0, min(D, Bw)) print(Aw)