import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int[] value = new int[4]; for (int i = 0; i < 4; i++) { value[i] = sc.nextInt(); } int min = Integer.MAX_VALUE; for (int a = 30; a >= 3; a--) { for (int b = a - 1; b >= 2; b--) { for (int c = b - 1; c >= 1; c--) { int[] counts = new int[31]; Arrays.fill(counts, Integer.MAX_VALUE / 10); counts[0] = 0; for (int i = 0; i + a <= 30; i++) { counts[i + a] = Math.min(counts[i + a], counts[i] + 1); } for (int i = 0; i + b <= 30; i++) { counts[i + b] = Math.min(counts[i + b], counts[i] + 1); } for (int i = 0; i + c <= 30; i++) { counts[i + c] = Math.min(counts[i + c], counts[i] + 1); } int sum = 0; for (int x : value) { sum += counts[x]; } min = Math.min(min, sum); } } } System.out.println(min); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }