import sys input = sys.stdin.readline def main(): x, y, z, w = map(int, input().split()) M = max(x, y, z, w, 3) ans = float('inf') for a in range(1, M+1): for b in range(1, a): for c in range(1, b): D = [0] + [float('inf')]*M for i in range(M): for j in [a, b, c]: if i+j <= M: D[i+j] = min(D[i+j], D[i]+1) ans = min(ans, D[x]+D[y]+D[z]+D[w]) print(ans) if __name__ == '__main__': main()