import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class computers_sm_wrong_4 {
	final int wrong = Integer.parseInt(""
			+ this.getClass().getName().substring(
					this.getClass().getName().lastIndexOf('_') + 1)); // Line 29

	int[] a, b;
	int res;

	int[][] D = { { 0, 0 }, { 1, 1 }, { 0, 2 }, { 2, 0 }, { 1, 2 }, { 2, 1 },
			{ 2, 2 } };

	private void solve() {
		a = new int[3];
		for (int i = 0; i < a.length; i++) {
			a[i] = nextInt(0, 100);
		}
		b = new int[3];
		for (int i = 0; i < b.length; i++) {
			b[i] = nextInt(0, 100);
		}
		res = 0;
		for (int i = 0; i < D.length; i++) {
			if (i == wrong)
				continue;
			match(D[i][0], D[i][1]);
		}
		out.println(res);
	}

	void match(int i, int j) {
		int d = Math.min(a[i], b[j]);
		a[i] -= d;
		b[j] -= d;
		res += d;
	}

	void myAssert(boolean b) {
		if (!b)
			throw new AssertionError();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	public void run() {
		try {
			br = new BufferedReader(new FileReader("computers.in"));
			out = new PrintWriter("computers.out");
			solve();
			out.close();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}

	}

	int nextInt(int a, int b) {
		int x = Integer.parseInt(nextToken());
		if (x < a || x > b)
			throw new AssertionError();
		return x;
	}

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

	public static void main(String[] args) {
		new computers_sm_wrong_4().run();
	}

}
