import java.util.*; public class Exercise118{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); int[] a = new int[2]; int[] b = new int[2]; a[0] = sc.nextInt(); a[1] = sc.nextInt(); b[0] = sc.nextInt(); b[1] = sc.nextInt(); int f = sc.nextInt(); int s = sc.nextInt(); b[0] += Math.min(f - a[1], a[0]); a[0] -= Math.min(f - a[1], a[0]); a[0] += Math.min(s, b[0]); System.out.println(a[0]); } }