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