import java.util.*; import java.lang.*; import java.io.*; class Ideone{ public static void main(String[] args) throws Exception{ // your code goes here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] lines = br.readLine().split(" "); int aw = Integer.parseInt(lines[0]); int ab = Integer.parseInt(lines[1]); lines = br.readLine().split(" "); int bw = Integer.parseInt(lines[0]); int bb = Integer.parseInt(lines[1]); lines = br.readLine().split(" "); int c = Integer.parseInt(lines[0]); int d = Integer.parseInt(lines[1]); c -= ab; if(c>0){ aw-=c; bw+=c; } System.out.println(aw+Math.min(bw,d)); } }