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