package no149; import java.util.Scanner; public 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 c = sc.nextInt(); int d = sc.nextInt(); int db = Math.min(ab, c); aw -= (c - db); bw += (c - db); ab -= db; bb += db; int dw = Math.min(bw, d); bw -= dw; aw += dw; System.out.println(aw); } }