import java.io.*; import java.util.*; class Main { public static void out (Object o) { System.out.println(o); } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] line1 = br.readLine().split(" "); String[] line2 = br.readLine().split(" "); String[] line3 = br.readLine().split(" "); int aw = Integer.parseInt(line1[0]); int ab = Integer.parseInt(line1[1]); int bw = Integer.parseInt(line2[0]); int bb = Integer.parseInt(line2[1]); int c = Integer.parseInt(line3[0]); int d = Integer.parseInt(line3[1]); if (c > ab) { c -= ab; aw -= c; bw += c; } out(aw + Math.min(d , bw)); } }