import sys
input = sys.stdin.readline
INF = float("inf")
# 解説参照

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse=True)  # 使用可能は数字は大きい順にソートしておく
    cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    # dp[i]:= マッチi本で作れる最大桁数
    dp = [-1] * (n + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        for aj in a:
            if i - cost[aj] < 0:
                continue
            dp[i] = max(dp[i], dp[i - cost[aj]] + 1)
    digits = dp[n]
    ans = ""
    rest = n
    # 上から貪欲
    while digits:
        for aj in a:
            if rest - cost[aj] < 0:
                continue
            if dp[rest - cost[aj]] == digits - 1:
                ans += str(aj)
                rest -= cost[aj]
                digits -= 1
                break
    print(ans)


if __name__ == '__main__':
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline INF = float("inf") INF float("inf") float "inf" def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse=True)  # 使用可能は数字は大きい順にソートしておく
    cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    # dp[i]:= マッチi本で作れる最大桁数
    dp = [-1] * (n + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        for aj in a:
            if i - cost[aj] < 0:
                continue
            dp[i] = max(dp[i], dp[i - cost[aj]] + 1)
    digits = dp[n]
    ans = ""
    rest = n
    # 上から貪欲
    while digits:
        for aj in a:
            if rest - cost[aj] < 0:
                continue
            if dp[rest - cost[aj]] == digits - 1:
                ans += str(aj)
                rest -= cost[aj]
                digits -= 1
                break
    print(ans) main 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 a.sort(reverse=True) a.sort a sort reverse=True reverse True cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6] cost [-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 i in range(1, n + 1):
        for aj in a:
            if i - cost[aj] < 0:
                continue
            dp[i] = max(dp[i], dp[i - cost[aj]] + 1)
     i range(1, n + 1) range 1 n + 1 n 1 for aj in a:
            if i - cost[aj] < 0:
                continue
            dp[i] = max(dp[i], dp[i - cost[aj]] + 1)
     aj a if i - cost[aj] < 0:
                continue
             i - cost[aj] < 0 i - cost[aj] i cost[aj] cost aj 0 continue dp[i] = max(dp[i], dp[i - cost[aj]] + 1) dp[i] dp i max(dp[i], dp[i - cost[aj]] + 1) max dp[i] dp i dp[i - cost[aj]] + 1 dp[i - cost[aj]] dp i - cost[aj] i cost[aj] cost aj 1 digits = dp[n] digits dp[n] dp n ans = "" ans "" rest = n rest n while digits:
        for aj in a:
            if rest - cost[aj] < 0:
                continue
            if dp[rest - cost[aj]] == digits - 1:
                ans += str(aj)
                rest -= cost[aj]
                digits -= 1
                break
     digits for aj in a:
            if rest - cost[aj] < 0:
                continue
            if dp[rest - cost[aj]] == digits - 1:
                ans += str(aj)
                rest -= cost[aj]
                digits -= 1
                break
     aj a if rest - cost[aj] < 0:
                continue
             rest - cost[aj] < 0 rest - cost[aj] rest cost[aj] cost aj 0 continue if dp[rest - cost[aj]] == digits - 1:
                ans += str(aj)
                rest -= cost[aj]
                digits -= 1
                break
     dp[rest - cost[aj]] == digits - 1 dp[rest - cost[aj]] dp rest - cost[aj] rest cost[aj] cost aj digits - 1 digits 1 ans += str(aj) ans str(aj) str aj rest -= cost[aj] rest cost[aj] cost aj digits -= 1 digits 1 break print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main input = sys.stdin.readline sys.stdin.readline input def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse=True)  # 使用可能は数字は大きい順にソートしておく
    cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    # dp[i]:= マッチi本で作れる最大桁数
    dp = [-1] * (n + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        for aj in a:
            if i - cost[aj] < 0:
                continue
            dp[i] = max(dp[i], dp[i - cost[aj]] + 1)
    digits = dp[n]
    ans = ""
    rest = n
    # 上から貪欲
    while digits:
        for aj in a:
            if rest - cost[aj] < 0:
                continue
            if dp[rest - cost[aj]] == digits - 1:
                ans += str(aj)
                rest -= cost[aj]
                digits -= 1
                break
    print(ans) def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse=True)  # 使用可能は数字は大きい順にソートしておく
    cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    # dp[i]:= マッチi本で作れる最大桁数
    dp = [-1] * (n + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        for aj in a:
            if i - cost[aj] < 0:
                continue
            dp[i] = max(dp[i], dp[i - cost[aj]] + 1)
    digits = dp[n]
    ans = ""
    rest = n
    # 上から貪欲
    while digits:
        for aj in a:
            if rest - cost[aj] < 0:
                continue
            if dp[rest - cost[aj]] == digits - 1:
                ans += str(aj)
                rest -= cost[aj]
                digits -= 1
                break
    print(ans) main INF = float("inf") float("inf") INF
import sys
input = sys.stdin.readline
INF = float("inf")
# 解説参照

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse=True)  # 使用可能は数字は大きい順にソートしておく
    cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    # dp[i]:= マッチi本で作れる最大桁数
    dp = [-1] * (n + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        for aj in a:
            if i - cost[aj] < 0:
                continue
            dp[i] = max(dp[i], dp[i - cost[aj]] + 1)
    digits = dp[n]
    ans = ""
    rest = n
    # 上から貪欲
    while digits:
        for aj in a:
            if rest - cost[aj] < 0:
                continue
            if dp[rest - cost[aj]] == digits - 1:
                ans += str(aj)
                rest -= cost[aj]
                digits -= 1
                break
    print(ans)


if __name__ == '__main__':
    main()
