import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int aw=sc.nextInt(); int ab=sc.nextInt(); int bw=sc.nextInt(); int bb=sc.nextInt(); int c=sc.nextInt(); int d=sc.nextInt(); if(ab>=c){ ab-=c; bb+=c; } else{ aw-=(c-ab); bw+=(c-ab); bb+=ab; ab=0; } if(bw>=d) aw+=d; else aw+=bw; System.out.println(aw); } } }