import java.util.*; public class Run { final static int M = 1000000007; public static void main (String arg[]) { Scanner scan = new Scanner(System.in); int Aw,Ab,Bw,Bb,C,D; Aw = scan.nextInt(); Ab = scan.nextInt(); Bw = scan.nextInt(); Bb = scan.nextInt(); C = scan.nextInt(); D = scan.nextInt(); int r; if (Ab < C) { r = C - Ab; Aw -= r; Bw += r; if (Bw > D) Aw += D; else Aw += Bw; } else { if (Bw > D) Aw += D; else Aw += Bw; } System.out.println(Aw); } }