Aw, Ab = map(int, raw_input().split())
Bw, Bb = map(int, raw_input().split())
C, D = map(int, raw_input().split())
moveatobwhite = 0
moveatobblack = 0
if Ab >= C:
	moveatobblack = C
else:
	moveatobblack = Ab
	moveatobwhite = C - Ab
Aw -= moveatobwhite
Ab -= moveatobblack
Bw += moveatobwhite
Bb += moveatobblack
movebtoawhite = 0
movebtoablack = 0
if Bw >= D:
	movebtoawhite = D
else:
	movebtoawhite = Bw
print Aw + movebtoawhite