import sys
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

A = list(map(int, input().split()))

match_dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

dp = ["0"] * 10010

dp[0] = ""

def greater(x, y):
    if len(x) == len(y):
        return max(x, y)
    else:
        return x if len(x) > len(y) else y

for i in range(N):
    if dp[i] != "0":
        for num in A:
            dp[i+match_dict[num]] = greater(dp[i+match_dict[num]], dp[i]+str(num))

print(dp[N]) import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split match_dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6} match_dict {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 dp = ["0"] * 10010 dp ["0"] * 10010 ["0"] "0" 10010 dp[0] = "" dp[0] dp 0 "" def greater(x, y):
    if len(x) == len(y):
        return max(x, y)
    else:
        return x if len(x) > len(y) else y greater if len(x) == len(y):
        return max(x, y)
    else:
        return x if len(x) > len(y) else y len(x) == len(y) len(x) len x len(y) len y return max(x, y) max(x, y) max x y return x if len(x) > len(y) else y x if len(x) > len(y) else y len(x) > len(y) len(x) len x len(y) len y x y x x y y for i in range(N):
    if dp[i] != "0":
        for num in A:
            dp[i+match_dict[num]] = greater(dp[i+match_dict[num]], dp[i]+str(num)) i range(N) range N if dp[i] != "0":
        for num in A:
            dp[i+match_dict[num]] = greater(dp[i+match_dict[num]], dp[i]+str(num)) dp[i] != "0" dp[i] dp i "0" for num in A:
            dp[i+match_dict[num]] = greater(dp[i+match_dict[num]], dp[i]+str(num)) num A dp[i+match_dict[num]] = greater(dp[i+match_dict[num]], dp[i]+str(num)) dp[i+match_dict[num]] dp i+match_dict[num] i match_dict[num] match_dict num greater(dp[i+match_dict[num]], dp[i]+str(num)) greater dp[i+match_dict[num]] dp i+match_dict[num] i match_dict[num] match_dict num dp[i]+str(num) dp[i] dp i str(num) str num print(dp[N]) print dp[N] dp N M = map(int, input().split()) map(int, input().split()) M dp = ["0"] * 10010 ["0"] * 10010 dp match_dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6} {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6} match_dict def greater(x, y):
    if len(x) == len(y):
        return max(x, y)
    else:
        return x if len(x) > len(y) else y def greater(x, y):
    if len(x) == len(y):
        return max(x, y)
    else:
        return x if len(x) > len(y) else y greater A = list(map(int, input().split())) list(map(int, input().split())) A input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input N, M = map(int, input().split()) map(int, input().split()) N
import sys
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

A = list(map(int, input().split()))

match_dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

dp = ["0"] * 10010

dp[0] = ""

def greater(x, y):
    if len(x) == len(y):
        return max(x, y)
    else:
        return x if len(x) > len(y) else y

for i in range(N):
    if dp[i] != "0":
        for num in A:
            dp[i+match_dict[num]] = greater(dp[i+match_dict[num]], dp[i]+str(num))

print(dp[N])