# import pypyjit;pypyjit.set_param("max_unroll_recursion=-1") # from bisect import * # from collections import * # from heapq import * # from itertools import * # from math import * # from datetime import * # from decimal import * # PyPyだと遅い # from string import ascii_lowercase,ascii_uppercase # import numpy as np import sys # sys.setrecursionlimit(10**6) # PyPyだと遅い INF = 10**18 MOD = 998244353 # MOD = 10**9 + 7 File = sys.stdin def input(): return File.readline()[:-1] # /////////////////////////////////////////////////////////////////////////// N = int(input()) A, B, C = map(int, input().split()) dp = [-1] * (N + 1) dp[0] = 0 l = [(3, A), (5, B), (10, C)] for i in range(1, N + 1): for j, k in l: if i - j >= 0 and dp[i - j] != -1: dp[i] = max(dp[i], dp[i - j] + k) print(dp[N])