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

public class pobeda_vd_assert50 {
	
	boolean can(long size, long a, long b, long c, long d) {
		return size*size <= Math.min(a, b) + Math.min(c, d);
	}

	public long solveFast(long a, long b, long c, long d) {
		if (a > 100000 || b > 100000 || c > 100000 || d > 100000) {
			throw new AssertionError();
		}
		long sum2 = 2 * (a + b + c + d);
		long l = 0;
		long r = (long) (Math.sqrt(sum2));
		while (r * r <= sum2) {
			r++;
		}
		r = Math.max(r, 5);
		while (l < r - 1) {
			long x = (l + r) / 2;
			if (can(x, a, b, c, d)) {
				l = x;
			} else {
				r = x;
			}
		}
		return l;
	}
	

	public long solveSlow(long a, long b, long c, long d) {
		for (int i = 1;; i++) {
			if (!can(i, a, b, c, d)) {
				return i-1;
			}
		}
	}

	final String fileName = "pobeda_vd_".split("_")[0];

	public void run() throws IOException {
		br = new BufferedReader(new FileReader(fileName + ".in"));
		out = new PrintWriter(fileName + ".out");
		out.println(solveFast(nextLong(), nextLong(), nextLong(), nextLong()));
		out.close();
		br.close();
	}

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

	BufferedReader br;
	StringTokenizer str;
	PrintWriter out;

	String next() throws IOException {
		while (str == null || !str.hasMoreTokens()) {
			str = new StringTokenizer(br.readLine());
		}
		return str.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

}
