import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); try { String[] abox = read.readLine().split(" "); String[] bbox = read.readLine().split(" "); String[] cbox = read.readLine().split(" "); int[] a = new int[2]; int[] b = new int[2]; int[] c = new int[2]; for (int i = 0; i < 2; ++i) { a[i] = Integer.parseInt(abox[i]); b[i] = Integer.parseInt(bbox[i]); c[i] = Integer.parseInt(cbox[i]); } if (a[1] - c[0] < 0) { b[0] += Math.abs(a[1] - c[0]); a[0] += a[1] - c[0]; } if (b[0] - c[1] < 0) { a[0] += b[0]; } else { a[0] += c[1]; } System.out.println(a[0]); } catch (Exception e) { e.printStackTrace(); } } }