import std.stdio, std.conv, std.string, std.range, std.math, std.algorithm; void main() { auto input = stdin.byLine.join(" ").split.to!(int[]); auto Aw = input[0], Ab = input[1], Bw = input[2], Bb = input[3], C = input[4], D = input[5]; (Aw - max(C - Ab, 0) + min(Bw + max(C - Ab, 0), D)).writeln; }