import java.io.BufferedInputStream; import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; import java.util.Map.Entry; import java.util.concurrent.ConcurrentSkipListSet; public class Main { public static final int C = 1000000007; static final int CY = 1000000000; //static boolean MAP[][]; static int K; static int N; static double P; static String S; static int M; static int MAX = -1; //static int tic[][]; static int T[][]; static int Y[]; static double W[]; //static int max; static long DP[]; static int ST[][]; //static int p[]; //static ArrayList> al; static ConcurrentSkipListSet TS; static ArrayList AL; //static int a[][]; //static char[][] ch; //static ArrayList> al; //static String a[]; //static String str; public static void main(String[] args) { StringBuilder sb = new StringBuilder(); BufferedInputStream bs = new BufferedInputStream(System.in); Scanner sc = new Scanner(bs); int aw = sc.nextInt(); int ab = sc.nextInt(); int bw = sc.nextInt(); int bb = sc.nextInt(); int c = sc.nextInt(); int d = sc.nextInt(); long ans = 0; ans += aw; int ch = Math.max(0, c - ab); ans -= ch; bw += ch; ans += Math.min(d,bw); System.out.println(ans); } }