import java.util.*; import static java.lang.Math.*; public class Main { private void solve() { Scanner sc = new Scanner(System.in); int aw = sc.nextInt(); int ab = sc.nextInt(); int bw = sc.nextInt(); int bb = sc.nextInt(); int c = sc.nextInt(); int d = sc.nextInt(); int lagmark = min(ab, c); aw -= c - lagmark; bw += c - lagmark; System.out.println(aw + min(bw, d)); } public static void main(String[] args) { new Main().solve(); } }