# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

tocnt = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

def compare(a, b):
    if a is None:
        return b
    if len(a) > len(b):
        return a
    if len(a) < len(b):
        return b
    return max(a, b)

N, M = MAP()
A = LIST()

# dp[i] := マッチをi本使った状態での最大値
dp = [None] * (N+1)
dp[0] = ''
for i in range(N):
    if dp[i] is None:
        continue
    for j in A:
        cnt = tocnt[j]
        if i+cnt <= N:
            dp[i+cnt] = compare(dp[i+cnt], dp[i] + str(j))
print(dp[N]) import sys sys def input(): return sys.stdin.readline().strip() input [c] * b for i in range(a) for i in range(a) i range(a) range a for i in range(a) [c] * b [c] c b def list2d(a, b, c): return [[c] * b for i in range(a)] list2d a a b b c c [[d] * c for j in range(b)] for i in range(a) for i in range(a) i range(a) range a for i in range(a) [[d] * c for j in range(b)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] list3d a a b b c c d d [[[e] * d for j in range(c)] for j in range(b)] for i in range(a) for i in range(a) i range(a) range a for i in range(a) [[[e] * d for j in range(c)] for j in range(b)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] list4d a a b b c c d d e e def ceil(x, y=1): return int(-(-x // y)) ceil x x y=1 y 1 def INT(): return int(input()) INT def MAP(): return map(int, input().split()) MAP INT() for i in range(N) for i in range(N) i range(N) range N for i in range(N) INT() INT def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] LIST N=None N None def Yes(): print('Yes') Yes def No(): print('No') No def YES(): print('YES') YES def NO(): print('NO') NO sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = 10 ** 18 INF 10 ** 18 10 18 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 tocnt = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} tocnt {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 def compare(a, b):
    if a is None:
        return b
    if len(a) > len(b):
        return a
    if len(a) < len(b):
        return b
    return max(a, b) compare if a is None:
        return b
     a is None a None return b b if len(a) > len(b):
        return a
     len(a) > len(b) len(a) len a len(b) len b return a a if len(a) < len(b):
        return b
     len(a) < len(b) len(a) len a len(b) len b return b b return max(a, b) max(a, b) max a b a a b b N, M = MAP() N MAP() MAP M A = LIST() A LIST() LIST 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):
    if dp[i] is None:
        continue
    for j in A:
        cnt = tocnt[j]
        if i+cnt <= N:
            dp[i+cnt] = compare(dp[i+cnt], dp[i] + str(j)) i range(N) range N if dp[i] is None:
        continue
     dp[i] is None dp[i] dp i None continue for j in A:
        cnt = tocnt[j]
        if i+cnt <= N:
            dp[i+cnt] = compare(dp[i+cnt], dp[i] + str(j)) j A cnt = tocnt[j] cnt tocnt[j] tocnt j if i+cnt <= N:
            dp[i+cnt] = compare(dp[i+cnt], dp[i] + str(j)) i+cnt <= N i+cnt i cnt N dp[i+cnt] = compare(dp[i+cnt], dp[i] + str(j)) dp[i+cnt] dp i+cnt i cnt compare(dp[i+cnt], dp[i] + str(j)) compare dp[i+cnt] dp i+cnt i cnt dp[i] + str(j) dp[i] dp i str(j) str j print(dp[N]) print dp[N] dp N def NO(): print('NO') def NO(): print('NO') NO def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] LIST def compare(a, b):
    if a is None:
        return b
    if len(a) > len(b):
        return a
    if len(a) < len(b):
        return b
    return max(a, b) def compare(a, b):
    if a is None:
        return b
    if len(a) > len(b):
        return a
    if len(a) < len(b):
        return b
    return max(a, b) compare def list2d(a, b, c): return [[c] * b for i in range(a)] def list2d(a, b, c): return [[c] * b for i in range(a)] list2d def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] list3d def YES(): print('YES') def YES(): print('YES') YES def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input def INT(): return int(input()) def INT(): return int(input()) INT M = MAP() MAP() M cnt = tocnt[j] tocnt[j] cnt N, M = MAP() MAP() N INF = 10 ** 18 10 ** 18 INF def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] list4d tocnt = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} tocnt dp = [None] * (N+1) [None] * (N+1) dp def ceil(x, y=1): return int(-(-x // y)) def ceil(x, y=1): return int(-(-x // y)) ceil def No(): print('No') def No(): print('No') No A = LIST() LIST() A MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD def Yes(): print('Yes') def Yes(): print('Yes') Yes
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

tocnt = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

def compare(a, b):
    if a is None:
        return b
    if len(a) > len(b):
        return a
    if len(a) < len(b):
        return b
    return max(a, b)

N, M = MAP()
A = LIST()

# dp[i] := マッチをi本使った状態での最大値
dp = [None] * (N+1)
dp[0] = ''
for i in range(N):
    if dp[i] is None:
        continue
    for j in A:
        cnt = tocnt[j]
        if i+cnt <= N:
            dp[i+cnt] = compare(dp[i+cnt], dp[i] + str(j))
print(dp[N])
