def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    match = [0,2,5,5,4,5,6,3,7,6]
    dp = [-1] * (N + 10)
    dp[0] = 0
    for i in range(N):
        if dp[i] != -1:
            for a in A:
                dp[i+match[a]] = max(dp[i+match[a]], dp[i] * 10 + a)
        
    print(dp[N])


if __name__ == "__main__":
    main() def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    match = [0,2,5,5,4,5,6,3,7,6]
    dp = [-1] * (N + 10)
    dp[0] = 0
    for i in range(N):
        if dp[i] != -1:
            for a in A:
                dp[i+match[a]] = max(dp[i+match[a]], dp[i] * 10 + a)
        
    print(dp[N]) 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 match = [0,2,5,5,4,5,6,3,7,6] match [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp = [-1] * (N + 10) dp [-1] * (N + 10) [-1] -1 N + 10 N 10 dp[0] = 0 dp[0] dp 0 0 for i in range(N):
        if dp[i] != -1:
            for a in A:
                dp[i+match[a]] = max(dp[i+match[a]], dp[i] * 10 + a)
        
     i range(N) range N if dp[i] != -1:
            for a in A:
                dp[i+match[a]] = max(dp[i+match[a]], dp[i] * 10 + a)
        
     dp[i] != -1 dp[i] dp i -1 for a in A:
                dp[i+match[a]] = max(dp[i+match[a]], dp[i] * 10 + a)
        
     a A dp[i+match[a]] = max(dp[i+match[a]], dp[i] * 10 + a) dp[i+match[a]] dp i+match[a] i match[a] match a max(dp[i+match[a]], dp[i] * 10 + a) max dp[i+match[a]] dp i+match[a] i match[a] match a dp[i] * 10 + a dp[i] * 10 dp[i] dp i 10 a print(dp[N]) print dp[N] dp N if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    match = [0,2,5,5,4,5,6,3,7,6]
    dp = [-1] * (N + 10)
    dp[0] = 0
    for i in range(N):
        if dp[i] != -1:
            for a in A:
                dp[i+match[a]] = max(dp[i+match[a]], dp[i] * 10 + a)
        
    print(dp[N]) def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    match = [0,2,5,5,4,5,6,3,7,6]
    dp = [-1] * (N + 10)
    dp[0] = 0
    for i in range(N):
        if dp[i] != -1:
            for a in A:
                dp[i+match[a]] = max(dp[i+match[a]], dp[i] * 10 + a)
        
    print(dp[N]) main
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    match = [0,2,5,5,4,5,6,3,7,6]
    dp = [-1] * (N + 10)
    dp[0] = 0
    for i in range(N):
        if dp[i] != -1:
            for a in A:
                dp[i+match[a]] = max(dp[i+match[a]], dp[i] * 10 + a)
        
    print(dp[N])


if __name__ == "__main__":
    main()