def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2

hon = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))
dp = ["N"] * (n + 1)
dp[0]=""
for i in range(2, n + 1):
    for a in aa:
        if i - hon[a] < 0: continue
        dp[i] = smax(dp[i], dp[i - hon[a]] + str(a))
print(dp[-1]) def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2 smax if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
     s1=="N" s1 "N" if s2[0]=="N":
            return "N"
        else:
            return s2
     s2[0]=="N" s2[0] s2 0 "N" return "N" "N" return s2 s2 if s2[0] == "N":
        return s1
     s2[0] == "N" s2[0] s2 0 "N" return s1 s1 l1 = len(s1) l1 len(s1) len s1 l2 = len(s2) l2 len(s2) len s2 if l1 == l2:
        return max(s1, s2)
     l1 == l2 l1 l2 return max(s1, s2) max(s1, s2) max s1 s2 if l1 > l2:
        return s1
     l1 > l2 l1 l2 return s1 s1 return s2 s2 s1 s1 s2 s2 hon = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] hon [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m aa = list(map(int, input().split())) aa list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp = ["N"] * (n + 1) dp ["N"] * (n + 1) ["N"] "N" n + 1 n 1 dp[0]="" dp[0] dp 0 "" for i in range(2, n + 1):
    for a in aa:
        if i - hon[a] < 0: continue
        dp[i] = smax(dp[i], dp[i - hon[a]] + str(a)) i range(2, n + 1) range 2 n + 1 n 1 for a in aa:
        if i - hon[a] < 0: continue
        dp[i] = smax(dp[i], dp[i - hon[a]] + str(a)) a aa if i - hon[a] < 0: continue
         i - hon[a] < 0 i - hon[a] i hon[a] hon a 0 dp[i] = smax(dp[i], dp[i - hon[a]] + str(a)) dp[i] dp i smax(dp[i], dp[i - hon[a]] + str(a)) smax dp[i] dp i dp[i - hon[a]] + str(a) dp[i - hon[a]] dp i - hon[a] i hon[a] hon a str(a) str a print(dp[-1]) print dp[-1] dp -1 def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2 def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2 smax n, m = map(int, input().split()) map(int, input().split()) n hon = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] hon dp = ["N"] * (n + 1) ["N"] * (n + 1) dp m = map(int, input().split()) map(int, input().split()) m aa = list(map(int, input().split())) list(map(int, input().split())) aa
def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2

hon = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))
dp = ["N"] * (n + 1)
dp[0]=""
for i in range(2, n + 1):
    for a in aa:
        if i - hon[a] < 0: continue
        dp[i] = smax(dp[i], dp[i - hon[a]] + str(a))
print(dp[-1])
