# D - Match Matching

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)

n_match = [-1,2,5,5,4,5,6,3,7,6]

dp = [-1] * (N+1) # dp[i]はちょうどi本のマッチ棒で作れる最も桁数の多い整数の桁数

dp[0] = 0
for idx in range(1,N+1):
    tmp = []
    for x in A:
        if idx - n_match[x] >= 0:
            tmp.append(dp[idx - n_match[x]] + 1)
    if tmp:
        dp[idx] = max(tmp)

ans = ""
rest_match = N
while len(ans) <= N//2 and rest_match > 0:
    for x in A:
        if rest_match - n_match[x] >= 0 and dp[rest_match - n_match[x]] == dp[rest_match] - 1:
            ans += str(x)
            rest_match -= n_match[x]
            break
            
print(ans) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = sorted(list(map(int, input().split())), reverse = True) A sorted(list(map(int, input().split())), reverse = True) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split reverse = True reverse True n_match = [-1,2,5,5,4,5,6,3,7,6] n_match [-1,2,5,5,4,5,6,3,7,6] -1 2 5 5 4 5 6 3 7 6 dp = [-1] * (N+1) dp [-1] * (N+1) [-1] -1 N+1 N 1 dp[0] = 0 dp[0] dp 0 0 for idx in range(1,N+1):
    tmp = []
    for x in A:
        if idx - n_match[x] >= 0:
            tmp.append(dp[idx - n_match[x]] + 1)
    if tmp:
        dp[idx] = max(tmp) idx range(1,N+1) range 1 N+1 N 1 tmp = [] tmp [] for x in A:
        if idx - n_match[x] >= 0:
            tmp.append(dp[idx - n_match[x]] + 1)
     x A if idx - n_match[x] >= 0:
            tmp.append(dp[idx - n_match[x]] + 1)
     idx - n_match[x] >= 0 idx - n_match[x] idx n_match[x] n_match x 0 tmp.append(dp[idx - n_match[x]] + 1) tmp.append tmp append dp[idx - n_match[x]] + 1 dp[idx - n_match[x]] dp idx - n_match[x] idx n_match[x] n_match x 1 if tmp:
        dp[idx] = max(tmp) tmp dp[idx] = max(tmp) dp[idx] dp idx max(tmp) max tmp ans = "" ans "" rest_match = N rest_match N while len(ans) <= N//2 and rest_match > 0:
    for x in A:
        if rest_match - n_match[x] >= 0 and dp[rest_match - n_match[x]] == dp[rest_match] - 1:
            ans += str(x)
            rest_match -= n_match[x]
            break
             len(ans) <= N//2 and rest_match > 0 len(ans) <= N//2 len(ans) len ans N//2 N 2 rest_match > 0 rest_match 0 for x in A:
        if rest_match - n_match[x] >= 0 and dp[rest_match - n_match[x]] == dp[rest_match] - 1:
            ans += str(x)
            rest_match -= n_match[x]
            break
             x A if rest_match - n_match[x] >= 0 and dp[rest_match - n_match[x]] == dp[rest_match] - 1:
            ans += str(x)
            rest_match -= n_match[x]
            break
             rest_match - n_match[x] >= 0 and dp[rest_match - n_match[x]] == dp[rest_match] - 1 rest_match - n_match[x] >= 0 rest_match - n_match[x] rest_match n_match[x] n_match x 0 dp[rest_match - n_match[x]] == dp[rest_match] - 1 dp[rest_match - n_match[x]] dp rest_match - n_match[x] rest_match n_match[x] n_match x dp[rest_match] - 1 dp[rest_match] dp rest_match 1 ans += str(x) ans str(x) str x rest_match -= n_match[x] rest_match n_match[x] n_match x break print(ans) print ans ans += str(x) str(x) ans rest_match -= n_match[x] n_match[x] rest_match n_match = [-1,2,5,5,4,5,6,3,7,6] [-1,2,5,5,4,5,6,3,7,6] n_match M = map(int, input().split()) map(int, input().split()) M dp = [-1] * (N+1) [-1] * (N+1) dp rest_match = N N rest_match ans = "" "" ans tmp = [] [] tmp N, M = map(int, input().split()) map(int, input().split()) N A = sorted(list(map(int, input().split())), reverse = True) sorted(list(map(int, input().split())), reverse = True) A
# D - Match Matching

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)

n_match = [-1,2,5,5,4,5,6,3,7,6]

dp = [-1] * (N+1) # dp[i]はちょうどi本のマッチ棒で作れる最も桁数の多い整数の桁数

dp[0] = 0
for idx in range(1,N+1):
    tmp = []
    for x in A:
        if idx - n_match[x] >= 0:
            tmp.append(dp[idx - n_match[x]] + 1)
    if tmp:
        dp[idx] = max(tmp)

ans = ""
rest_match = N
while len(ans) <= N//2 and rest_match > 0:
    for x in A:
        if rest_match - n_match[x] >= 0 and dp[rest_match - n_match[x]] == dp[rest_match] - 1:
            ans += str(x)
            rest_match -= n_match[x]
            break
            
print(ans)