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