import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    a = sorted(LI())

    t = [9,2,5,5,4,5,6,3,7,6]
    d = {}
    for c in a:
        d[t[c]] = c

    dp = [0] * (n+10)
    for i in range(n):
        if i > 0 and dp[i] < 1:
            continue
        di = dp[i] * 10
        for k,v in d.items():
            t = di + v
            if dp[i+k] < t:
                dp[i+k] = t

    return dp[n]


print(main())
 import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools math string itertools fractions heapq collections re array bisect sys copy functools sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 inf = 10**20 inf 10**20 10 20 eps = 1.0 / 10**10 eps 1.0 / 10**10 1.0 10**10 10 10 mod = 998244353 mod 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] dd [(-1,0),(0,1),(1,0),(0,-1)] (-1,0) -1 0 (0,1) 0 1 (1,0) 1 0 (0,-1) 0 -1 ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] ddn [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] (-1,0) -1 0 (-1,1) -1 1 (0,1) 0 1 (1,1) 1 1 (1,0) 1 0 (1,-1) 1 -1 (0,-1) 0 -1 (-1,-1) -1 -1 def LI(): return list(map(int, sys.stdin.readline().split())) LI list(map(int, l.split())) for l in sys.stdin.readlines() for l in sys.stdin.readlines() l sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines for l in sys.stdin.readlines() list(map(int, l.split())) list map(int, l.split()) map int l.split() l.split l split def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] LLI int(x)-1 for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x)-1 int(x) int x 1 def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] LI_ float(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() float(x) float x def LF(): return [float(x) for x in sys.stdin.readline().split()] LF def LS(): return sys.stdin.readline().split() LS def I(): return int(sys.stdin.readline()) I def F(): return float(sys.stdin.readline()) F def S(): return input() S def pf(s): return print(s, flush=True) pf s s def pe(s): return print(str(s), file=sys.stderr) pe s s def JA(a, sep): return sep.join(map(str, a)) JA a a sep sep def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) JAA a a s s t t def main():
    n,m = LI()
    a = sorted(LI())

    t = [9,2,5,5,4,5,6,3,7,6]
    d = {}
    for c in a:
        d[t[c]] = c

    dp = [0] * (n+10)
    for i in range(n):
        if i > 0 and dp[i] < 1:
            continue
        di = dp[i] * 10
        for k,v in d.items():
            t = di + v
            if dp[i+k] < t:
                dp[i+k] = t

    return dp[n] main n,m = LI() n LI() LI m a = sorted(LI()) a sorted(LI()) sorted LI() LI t = [9,2,5,5,4,5,6,3,7,6] t [9,2,5,5,4,5,6,3,7,6] 9 2 5 5 4 5 6 3 7 6 d = {} d {} for c in a:
        d[t[c]] = c

     c a d[t[c]] = c d[t[c]] d t[c] t c c dp = [0] * (n+10) dp [0] * (n+10) [0] 0 n+10 n 10 for i in range(n):
        if i > 0 and dp[i] < 1:
            continue
        di = dp[i] * 10
        for k,v in d.items():
            t = di + v
            if dp[i+k] < t:
                dp[i+k] = t

     i range(n) range n if i > 0 and dp[i] < 1:
            continue
         i > 0 and dp[i] < 1 i > 0 i 0 dp[i] < 1 dp[i] dp i 1 continue di = dp[i] * 10 di dp[i] * 10 dp[i] dp i 10 for k,v in d.items():
            t = di + v
            if dp[i+k] < t:
                dp[i+k] = t

     k v d.items() d.items d items t = di + v t di + v di v if dp[i+k] < t:
                dp[i+k] = t

     dp[i+k] < t dp[i+k] dp i+k i k t dp[i+k] = t dp[i+k] dp i+k i k t return dp[n] dp[n] dp n print(main()) print main() main def F(): return float(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) F def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] LLI def main():
    n,m = LI()
    a = sorted(LI())

    t = [9,2,5,5,4,5,6,3,7,6]
    d = {}
    for c in a:
        d[t[c]] = c

    dp = [0] * (n+10)
    for i in range(n):
        if i > 0 and dp[i] < 1:
            continue
        di = dp[i] * 10
        for k,v in d.items():
            t = di + v
            if dp[i+k] < t:
                dp[i+k] = t

    return dp[n] def main():
    n,m = LI()
    a = sorted(LI())

    t = [9,2,5,5,4,5,6,3,7,6]
    d = {}
    for c in a:
        d[t[c]] = c

    dp = [0] * (n+10)
    for i in range(n):
        if i > 0 and dp[i] < 1:
            continue
        di = dp[i] * 10
        for k,v in d.items():
            t = di + v
            if dp[i+k] < t:
                dp[i+k] = t

    return dp[n] main def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] LI_ def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS def LF(): return [float(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] LF dd = [(-1,0),(0,1),(1,0),(0,-1)] [(-1,0),(0,1),(1,0),(0,-1)] dd def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I inf = 10**20 10**20 inf def S(): return input() def S(): return input() S def pf(s): return print(s, flush=True) def pf(s): return print(s, flush=True) pf ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] ddn def LI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) LI def JA(a, sep): return sep.join(map(str, a)) def JA(a, sep): return sep.join(map(str, a)) JA def pe(s): return print(str(s), file=sys.stderr) def pe(s): return print(str(s), file=sys.stderr) pe eps = 1.0 / 10**10 1.0 / 10**10 eps def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) JAA mod = 998244353 998244353 mod
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    a = sorted(LI())

    t = [9,2,5,5,4,5,6,3,7,6]
    d = {}
    for c in a:
        d[t[c]] = c

    dp = [0] * (n+10)
    for i in range(n):
        if i > 0 and dp[i] < 1:
            continue
        di = dp[i] * 10
        for k,v in d.items():
            t = di + v
            if dp[i+k] < t:
                dp[i+k] = t

    return dp[n]


print(main())

