# -*- coding: utf-8 -*- Aw, Ab = map(int, raw_input().split()) Bw, Bb = map(int, raw_input().split()) C, D = map(int, raw_input().split()) # Aに残ってる最大の白 W = Aw + min(0, Ab - C) # Bに移動する白分追加 Bw += -min(0, Ab - C) print W + min(D, Bw)