import std.algorithm, std.array, std.container, std.range; import std.numeric, std.math, std.bigint, std.bitmanip, std.random; import std.string, std.conv, std.stdio, std.typecons; void main() { auto rd1 = readln.split.map!(to!int); auto aw = rd1[0], ab = rd1[1]; auto rd2 = readln.split.map!(to!int); auto bw = rd2[0], bb = rd2[1]; auto rd3 = readln.split.map!(to!int); auto c = rd3[0], d = rd3[1]; auto b1 = min(ab, c); aw -= c - b1; bw += c - b1; auto w2 = min(bw, d); aw += w2; writeln(aw); }