package P149;

import java.util.Scanner;

public class P149 {
	
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String x = sc.nextLine();
		String[] xstrs = x.split(" ",0);
		int Aw = Integer.parseInt(xstrs[0]);
		int Ab = Integer.parseInt(xstrs[1]);		
		
		String y = sc.nextLine();
		String[] ystrs = y.split(" ",0);
		int Bw = Integer.parseInt(ystrs[0]);
		int Bb = Integer.parseInt(ystrs[1]);		
		
		String z = sc.nextLine();
		String[] zstrs = z.split(" ",0);
		int C = Integer.parseInt(zstrs[0]);
		int D = Integer.parseInt(zstrs[1]);
		
		int Ans = 0;
		
		if (C <= Ab) {
			if (D <= Bw) {
				Ans = Aw + D;
			} else if (D > Bw) {
				Ans = Aw + Bw;
			}
		} else if (C > Ab) {
			if (D <= Bw+C-Ab) {
				Ans = Aw - (C - Ab) + D;
			} else if (D > Bw+C-Ab) {
				Ans = Aw + Bw;
			}
		}
		
				
		System.out.println(Ans);
	}
}