import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int aw = in.nextInt(); int ab = in.nextInt(); int bw = in.nextInt(); int bb = in.nextInt(); int c = in.nextInt(); int d = in.nextInt(); if(c > ab) { aw = aw - (c - ab); bw = bw + (c - ab); } if(d > bw) { aw = aw + bw; } else { aw = aw + d; } System.out.println(aw); in.close(); } }