import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import static java.lang.System.in; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String[] inputs = reader.readLine().split(" "); int aw = Integer.parseInt(inputs[0]); int ab = Integer.parseInt(inputs[1]); inputs = reader.readLine().split(" "); int bw = Integer.parseInt(inputs[0]); int bb = Integer.parseInt(inputs[1]); inputs = reader.readLine().split(" "); int c = Integer.parseInt(inputs[0]); int d = Integer.parseInt(inputs[1]); if (ab < c) { aw = aw - (c - ab); bw = bw + (c-ab); } if (bw < d) { aw = aw + bw; } else { aw = aw + d; } System.out.println(aw); } }