import java.util.Scanner; public class Main { public static void main(String[] a) { Scanner s = new Scanner(System.in); int[] p=new int[6]; int i=0,b;for(;6>i;)p[i++]=s.nextInt(); b=(p[4]-p[1]>0)?p[4]-p[1]:0; System.out.println(p[0]-b+((p[5]-p[2]-b>0)?p[2]+b:p[5])); } }