def main(): v0, v1, v2, v3 = map(int, input().split()) ans = float('inf') max = 31 for a in range(1, max): for b in range(a + 1, max): for c in range(b + 1, max): dp = [float('inf')] * max dp[0] = 0 for i in range(max - a): dp[i + a] = min(dp[i + a], dp[i] + 1) for i in range(max - b): dp[i + b] = min(dp[i + b], dp[i] + 1) for i in range(max - c): dp[i + c] = min(dp[i + c], dp[i] + 1) ans = min(ans, dp[v0] + dp[v1] + dp[v2] + dp[v3]) print(ans) if __name__ == '__main__': main()