def main():
    N, M, *A = map(int, open(0).read().split())

    C = [0, 1, 4, 4, 3, 4, 5, 2, 6, 5]

    dp = [0] * (N + 1)
    for i in range(N):
        dp[i + 1] = max(dp[i - C[a]] * 10 + a if i - C[a] >= 0 else -1 for a in A)

    print(dp[N])

if __name__ == '__main__':
    main() def main():
    N, M, *A = map(int, open(0).read().split())

    C = [0, 1, 4, 4, 3, 4, 5, 2, 6, 5]

    dp = [0] * (N + 1)
    for i in range(N):
        dp[i + 1] = max(dp[i - C[a]] * 10 + a if i - C[a] >= 0 else -1 for a in A)

    print(dp[N]) main N, M, *A = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split M *A A C = [0, 1, 4, 4, 3, 4, 5, 2, 6, 5] C [0, 1, 4, 4, 3, 4, 5, 2, 6, 5] 0 1 4 4 3 4 5 2 6 5 dp = [0] * (N + 1) dp [0] * (N + 1) [0] 0 N + 1 N 1 for i in range(N):
        dp[i + 1] = max(dp[i - C[a]] * 10 + a if i - C[a] >= 0 else -1 for a in A)

     i range(N) range N dp[i + 1] = max(dp[i - C[a]] * 10 + a if i - C[a] >= 0 else -1 for a in A) dp[i + 1] dp i + 1 i 1 max(dp[i - C[a]] * 10 + a if i - C[a] >= 0 else -1 for a in A) max dp[i - C[a]] * 10 + a if i - C[a] >= 0 else -1 i - C[a] >= 0 i - C[a] i C[a] C a 0 dp[i - C[a]] * 10 + a dp[i - C[a]] * 10 dp[i - C[a]] dp i - C[a] i C[a] C a 10 a -1 print(dp[N]) print dp[N] dp N if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N, M, *A = map(int, open(0).read().split())

    C = [0, 1, 4, 4, 3, 4, 5, 2, 6, 5]

    dp = [0] * (N + 1)
    for i in range(N):
        dp[i + 1] = max(dp[i - C[a]] * 10 + a if i - C[a] >= 0 else -1 for a in A)

    print(dp[N]) def main():
    N, M, *A = map(int, open(0).read().split())

    C = [0, 1, 4, 4, 3, 4, 5, 2, 6, 5]

    dp = [0] * (N + 1)
    for i in range(N):
        dp[i + 1] = max(dp[i - C[a]] * 10 + a if i - C[a] >= 0 else -1 for a in A)

    print(dp[N]) main
def main():
    N, M, *A = map(int, open(0).read().split())

    C = [0, 1, 4, 4, 3, 4, 5, 2, 6, 5]

    dp = [0] * (N + 1)
    for i in range(N):
        dp[i + 1] = max(dp[i - C[a]] * 10 + a if i - C[a] >= 0 else -1 for a in A)

    print(dp[N])

if __name__ == '__main__':
    main()
