Aw, Ab = map(int, input().split()) Bw, Bb = map(int, input().split()) C, D = map(int, input().split()) b = max(C, Ab) w = C - b Bw += w Bb += b w = max(D, Bw) b = D - w Aw += w Ab += b print(Aw)