N = int(input()) A, B, C = map(int, input().split()) dp = [-1 for i in range(N + 1)] dp[0] = 0 for i in range(N): if dp[i] != -1: if i+3 <= N: dp[i+3] = max(dp[i] + A , dp[i+3]) if i + 5 <= N: dp[i+5] = max(dp[i] + B , dp[i+5]) if i+10<= N: dp[i+10] = max(dp[i] + C , dp[i+10]) print(max(dp))