import java.util.Scanner; public class GO { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int aw,ab,bw,bb,c,d; aw = sc.nextInt(); ab = sc.nextInt(); bw = sc.nextInt(); bb = sc.nextInt(); c = sc.nextInt(); d = sc.nextInt(); if(ab >= c){ ab -= c; bb += c; } else { aw -= (c-ab); bw += (c-ab); bb += ab; ab = 0; } System.out.println(aw + Math.min(d, bw)); } }