def max_for_str(a, b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    else:#This case is unlikely to happen.
        for c1, c2 in zip(a, b):
            if c1 > c2:
                return a
            elif c1 < c2:
                return b
        return a
            
match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

N, M = map(int, input().split())
As = list(input().split())

dp = [None] * (N+1)
dp[0] = ""

for i in range(N+1):
    for A in As:
        if i - match[int(A)] >= 0 and not dp[i - match[int(A)]] is None:
            if dp[i] is None:
                dp[i] = A + dp[i - match[int(A)]]
            else:
                dp[i] = max_for_str(dp[i] , A + dp[i - match[int(A)]])

print(dp[N]) def max_for_str(a, b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    else:#This case is unlikely to happen.
        for c1, c2 in zip(a, b):
            if c1 > c2:
                return a
            elif c1 < c2:
                return b
        return a
             max_for_str if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    else:#This case is unlikely to happen.
        for c1, c2 in zip(a, b):
            if c1 > c2:
                return a
            elif c1 < c2:
                return b
        return a
             len(a) > len(b) len(a) len a len(b) len b return a a elif len(a) < len(b):
        return b
     len(a) < len(b) len(a) len a len(b) len b return b b for c1, c2 in zip(a, b):
            if c1 > c2:
                return a
            elif c1 < c2:
                return b
         c1 c2 zip(a, b) zip a b if c1 > c2:
                return a
            elif c1 < c2:
                return b
         c1 > c2 c1 c2 return a a elif c1 < c2:
                return b
         c1 < c2 c1 c2 return b b return a a a a b b 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 N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M As = list(input().split()) As list(input().split()) list input().split() ().split () input split dp = [None] * (N+1) dp [None] * (N+1) [None] None N+1 N 1 dp[0] = "" dp[0] dp 0 "" for i in range(N+1):
    for A in As:
        if i - match[int(A)] >= 0 and not dp[i - match[int(A)]] is None:
            if dp[i] is None:
                dp[i] = A + dp[i - match[int(A)]]
            else:
                dp[i] = max_for_str(dp[i] , A + dp[i - match[int(A)]]) i range(N+1) range N+1 N 1 for A in As:
        if i - match[int(A)] >= 0 and not dp[i - match[int(A)]] is None:
            if dp[i] is None:
                dp[i] = A + dp[i - match[int(A)]]
            else:
                dp[i] = max_for_str(dp[i] , A + dp[i - match[int(A)]]) A As if i - match[int(A)] >= 0 and not dp[i - match[int(A)]] is None:
            if dp[i] is None:
                dp[i] = A + dp[i - match[int(A)]]
            else:
                dp[i] = max_for_str(dp[i] , A + dp[i - match[int(A)]]) i - match[int(A)] >= 0 and not dp[i - match[int(A)]] is None i - match[int(A)] >= 0 i - match[int(A)] i match[int(A)] match int(A) int A 0 not dp[i - match[int(A)]] is None dp[i - match[int(A)]] is None dp[i - match[int(A)]] dp i - match[int(A)] i match[int(A)] match int(A) int A None if dp[i] is None:
                dp[i] = A + dp[i - match[int(A)]]
            else:
                dp[i] = max_for_str(dp[i] , A + dp[i - match[int(A)]]) dp[i] is None dp[i] dp i None dp[i] = A + dp[i - match[int(A)]] dp[i] dp i A + dp[i - match[int(A)]] A dp[i - match[int(A)]] dp i - match[int(A)] i match[int(A)] match int(A) int A dp[i] = max_for_str(dp[i] , A + dp[i - match[int(A)]]) dp[i] dp i max_for_str(dp[i] , A + dp[i - match[int(A)]]) max_for_str dp[i] dp i A + dp[i - match[int(A)]] A dp[i - match[int(A)]] dp i - match[int(A)] i match[int(A)] match int(A) int A print(dp[N]) print dp[N] dp N M = map(int, input().split()) map(int, input().split()) M dp = [None] * (N+1) [None] * (N+1) dp def max_for_str(a, b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    else:#This case is unlikely to happen.
        for c1, c2 in zip(a, b):
            if c1 > c2:
                return a
            elif c1 < c2:
                return b
        return a
             def max_for_str(a, b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    else:#This case is unlikely to happen.
        for c1, c2 in zip(a, b):
            if c1 > c2:
                return a
            elif c1 < c2:
                return b
        return a
             max_for_str N, M = map(int, input().split()) map(int, input().split()) N As = list(input().split()) list(input().split()) As match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] match
def max_for_str(a, b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    else:#This case is unlikely to happen.
        for c1, c2 in zip(a, b):
            if c1 > c2:
                return a
            elif c1 < c2:
                return b
        return a
            
match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

N, M = map(int, input().split())
As = list(input().split())

dp = [None] * (N+1)
dp[0] = ""

for i in range(N+1):
    for A in As:
        if i - match[int(A)] >= 0 and not dp[i - match[int(A)]] is None:
            if dp[i] is None:
                dp[i] = A + dp[i - match[int(A)]]
            else:
                dp[i] = max_for_str(dp[i] , A + dp[i - match[int(A)]])

print(dp[N])