import java.util.*; import java.math.*; import java.io.*; 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(); if(ab >= c) { bb += c; ab -= c; } else { bb += ab; bw += (c - ab); aw -= (c - ab); ab = 0; } if(bw >= d) { aw += d; bw -= d; } else { aw += bw; } System.out.println(aw); } }