import java.math.*; import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int aw=sc.nextInt(); int ab=sc.nextInt(); int bw=sc.nextInt(); int bb=sc.nextInt(); int f=sc.nextInt(); int s=sc.nextInt(); int temp=Math.max(0, f-ab); aw-=temp; bw+=temp; aw+=Math.min(bw, s); System.out.println(aw); } }