# coding:utf-8



import sys

import math

INF = float('inf')

MOD = 10 ** 9 + 7



def LI(): return [int(x) for x in sys.stdin.readline().split()]

def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

def II(): return int(sys.stdin.readline())

def SI(): return eval(input())





def main():

    n, m = LI()

    A = LI()

    A.sort()

    A.reverse()



    match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

    # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の桁数（-1: 作れない）

    dp = [-1] * (n + 1)

    dp[0] = 0

    res = [0] * (n + 1)

    for i in range(1, n + 1):

        for j in A:

            # 最上位桁の数字を決める

            # k: 最上位桁をjにしたときの残りのマッチの数

            k = i - match[j]

            if k < 0 or dp[k] == -1:

                continue



            if dp[i] < dp[k] + 1:

                dp[i] = dp[k] + 1

                res[i] = j * 10 ** dp[k] + res[k]



    return res[n]





print((main()))

# coding:utf-8



import sys

INF = float('inf')

MOD = 10 ** 9 + 7



def LI(): return [int(x) for x in sys.stdin.readline().split()]

def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

def II(): return int(sys.stdin.readline())

def SI(): return eval(input())





def main():

    n, m = LI()

    A = LI()



    match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]

    # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の値

    dp = [-INF] * (n + 10)

    dp[0] = 0

    for i in range(n):

        for a in A:

            j = i + match[a]

            dp[j] = max(dp[j], dp[i] * 10 + a)



    return dp[n]





print((main()))

# coding:utf-8
import sys
import math

INF = float("inf")
MOD = 10**9 + 7


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def LI_():
    return [int(x) - 1 for x in sys.stdin.readline().split()]


def LS():
    return sys.stdin.readline().split()


def II():
    return int(sys.stdin.readline())


def SI():
    return eval(input())


def main():
    n, m = LI()
    A = LI()
    A.sort()
    A.reverse()
    match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の桁数（-1: 作れない）
    dp = [-1] * (n + 1)
    dp[0] = 0
    res = [0] * (n + 1)
    for i in range(1, n + 1):
        for j in A:
            # 最上位桁の数字を決める
            # k: 最上位桁をjにしたときの残りのマッチの数
            k = i - match[j]
            if k < 0 or dp[k] == -1:
                continue
            if dp[i] < dp[k] + 1:
                dp[i] = dp[k] + 1
                res[i] = j * 10 ** dp[k] + res[k]
    return res[n]


print((main()))

# coding:utf-8
import sys

INF = float("inf")
MOD = 10**9 + 7


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def LI_():
    return [int(x) - 1 for x in sys.stdin.readline().split()]


def LS():
    return sys.stdin.readline().split()


def II():
    return int(sys.stdin.readline())


def SI():
    return eval(input())


def main():
    n, m = LI()
    A = LI()
    match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の値
    dp = [-INF] * (n + 10)
    dp[0] = 0
    for i in range(n):
        for a in A:
            j = i + match[a]
            dp[j] = max(dp[j], dp[i] * 10 + a)
    return dp[n]


print((main()))

-import math -    A.sort() -    A.reverse() -    match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] -    # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の桁数（-1: 作れない） -    dp = [-1] * (n + 1) +    match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] +    # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の値 +    dp = [-INF] * (n + 10) -    res = [0] * (n + 1) -    for i in range(1, n + 1): -        for j in A: -            # 最上位桁の数字を決める -            # k: 最上位桁をjにしたときの残りのマッチの数 -            k = i - match[j] -            if k < 0 or dp[k] == -1: -                continue -            if dp[i] < dp[k] + 1: -                dp[i] = dp[k] + 1 -                res[i] = j * 10 ** dp[k] + res[k] -    return res[n] +    for i in range(n): +        for a in A: +            j = i + match[a] +            dp[j] = max(dp[j], dp[i] * 10 + a) +    return dp[n]