class Bag { int white; int black; Bag(int x, int y) { this.white = x; this.black = y; } } public class No_149 { public static void main(String[] args) { java.util.Scanner sc = new java.util.Scanner(System.in); Bag A = new Bag(sc.nextInt(), sc.nextInt()); Bag B = new Bag(sc.nextInt(), sc.nextInt()); int select1 = sc.nextInt(); int select2 = sc.nextInt(); if (A.black < select1) { select1 -= A.black; B.black += A.black; A.black = 0; B.white += select1; A.white -= select1; } else { A.black -= select1; B.black += select1; } if (B.white < select2) { select2 -= B.white; A.white += B.white; B.white = 0; A.black += select2; B.black -= select2; } else { B.white -= select2; A.white += select2; } System.out.println(A.white); sc.close(); } }