import java.io.*;
import java.util.*;
import java.math.*;

public class computers_aa implements Runnable {

	public static void main(final String[] args) {
		new Thread(new computers_aa()).start();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;
	Random rand = new Random(this.hashCode());

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			br = new BufferedReader(new FileReader(FNAME + ".in"));
			out = new PrintWriter(FNAME + ".out");
			solve();
			out.close();
		} catch (final Throwable e) {
			e.printStackTrace();
			System.exit(566);
		}
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (final Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	void myAssert(final boolean u, final String message) {
		if (!u) {
			throw new Error("Assertion failed!!! " + message);
		}
	}

	int inBounds(final int x, final int l, final int r, final String name) {
		myAssert(l <= x && x <= r, name + " not in bounds!!! " + x
				+ " not in [" + l + ".." + r + "]");
		return x;
	}

	String FNAME = "computers";

	private void solve() throws IOException {
		int a1 = inBounds(nextInt(), 0, 100, "a1");
		int a2 = inBounds(nextInt(), 0, 100, "a2");
		int a3 = inBounds(nextInt(), 0, 100, "a3");
		int b1 = inBounds(nextInt(), 0, 100, "b1");
		int b2 = inBounds(nextInt(), 0, 100, "b2");
		int b3 = inBounds(nextInt(), 0, 100, "b3");
		myAssert(a1 + a2 + a3 == b1 + b2 + b3, "Sum does not match!!! ");
		int vga = Math.min(a1, b1);
		a1 -= vga;
		b1 -= vga;
		int dvi = Math.min(a2, b2);
		a2 -= dvi;
		b2 -= dvi;
		int anymixed = Math.min(a1 + a2, b3);
		b3 -= anymixed;
		int mixedany = Math.min(a3, b1 + b2);
		a3 -= mixedany;
		int mixed = Math.min(a3, b3);
		out.println(vga + dvi + mixed + anymixed + mixedany);
	}
}
