import java.util.*; 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 ans = aw; ans -= Math.max(0, c - ab); ans += Math.min(bw, d); System.out.println(ans); } }