from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

DEPMAX = 5

def foo(n,dep):
    if dep>DEPMAX or n<0:
        ret = "-1"
    elif n==0:
        ret = ""
    elif n%mn==0:
        ret = str(mni)*(n//mn)
    else:
        mxs = "-1"
        for x in a:
            v = foo(n-cs[x],dep+1)
            if v=="-1":
                continue
            vv = v+str(x)
            if int(vv)>int(mxs):
                mxs = vv
            vv = str(x)+v
            if int(vv)>int(mxs):
                mxs = vv
        ret = mxs
    #ddprint(f"foo n {n} k {k} ret {ret}")
    return ret

n,m = inm()
a = inl()
a.sort()
cs = [0,2,5,5,4,5,6,3,7,6]
mn = min([cs[x] for x in a])
for i in range(m-1,-1,-1):
    if cs[a[i]]==mn:
        mni = a[i]
        break
#k = (n+mn-1)//mn
#k = (n)//mn
#ddprint(f"mn {mn} mni {mni}")
#ddprint(a)
print(foo(n,0)) from sys import stdout printn = lambda x: stdout.write(str(x)) printn lambda x: stdout.write(str(x)) stdout.write(str(x)) stdout.write stdout write str(x) str x x inn = lambda : int(input()) inn lambda : int(input()) int(input()) int input() input inl   = lambda: list(map(int, input().split())) inl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split inm   = lambda:      map(int, input().split()) inm lambda:      map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split ins = lambda : input().strip() ins lambda : input().strip() input().strip() ().strip () input strip DBG = True DBG True BIG = 999999999 BIG 999999999 R = 10**9 + 7 R 10**9 + 7 10**9 10 9 7 def ddprint(x):
  if DBG:
    print(x) ddprint if DBG:
    print(x) DBG print(x) print x x x DEPMAX = 5 DEPMAX 5 def foo(n,dep):
    if dep>DEPMAX or n<0:
        ret = "-1"
    elif n==0:
        ret = ""
    elif n%mn==0:
        ret = str(mni)*(n//mn)
    else:
        mxs = "-1"
        for x in a:
            v = foo(n-cs[x],dep+1)
            if v=="-1":
                continue
            vv = v+str(x)
            if int(vv)>int(mxs):
                mxs = vv
            vv = str(x)+v
            if int(vv)>int(mxs):
                mxs = vv
        ret = mxs
    #ddprint(f"foo n {n} k {k} ret {ret}")
    return ret foo if dep>DEPMAX or n<0:
        ret = "-1"
    elif n==0:
        ret = ""
    elif n%mn==0:
        ret = str(mni)*(n//mn)
    else:
        mxs = "-1"
        for x in a:
            v = foo(n-cs[x],dep+1)
            if v=="-1":
                continue
            vv = v+str(x)
            if int(vv)>int(mxs):
                mxs = vv
            vv = str(x)+v
            if int(vv)>int(mxs):
                mxs = vv
        ret = mxs
    #ddprint(f"foo n {n} k {k} ret {ret}")
     dep>DEPMAX or n<0 dep>DEPMAX dep DEPMAX n<0 n 0 ret = "-1" ret "-1" elif n==0:
        ret = ""
     n==0 n 0 ret = "" ret "" elif n%mn==0:
        ret = str(mni)*(n//mn)
     n%mn==0 n%mn n mn 0 ret = str(mni)*(n//mn) ret str(mni)*(n//mn) str(mni) str mni n//mn n mn mxs = "-1" mxs "-1" for x in a:
            v = foo(n-cs[x],dep+1)
            if v=="-1":
                continue
            vv = v+str(x)
            if int(vv)>int(mxs):
                mxs = vv
            vv = str(x)+v
            if int(vv)>int(mxs):
                mxs = vv
         x a v = foo(n-cs[x],dep+1) v foo(n-cs[x],dep+1) foo n-cs[x] n cs[x] cs x dep+1 dep 1 if v=="-1":
                continue
             v=="-1" v "-1" continue vv = v+str(x) vv v+str(x) v str(x) str x if int(vv)>int(mxs):
                mxs = vv
             int(vv)>int(mxs) int(vv) int vv int(mxs) int mxs mxs = vv mxs vv vv = str(x)+v vv str(x)+v str(x) str x v if int(vv)>int(mxs):
                mxs = vv
         int(vv)>int(mxs) int(vv) int vv int(mxs) int mxs mxs = vv mxs vv ret = mxs ret mxs return ret ret n n dep dep n,m = inm() n inm() inm m a = inl() a inl() inl a.sort() a.sort a sort cs = [0,2,5,5,4,5,6,3,7,6] cs [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 cs[x] for x in a for x in a x a for x in a cs[x] cs x mn = min([cs[x] for x in a]) mn min([cs[x] for x in a]) min [cs[x] for x in a] for i in range(m-1,-1,-1):
    if cs[a[i]]==mn:
        mni = a[i]
        break
#k = (n+mn-1)//mn
#k = (n)//mn
#ddprint(f"mn {mn} mni {mni}")
#ddprint(a) i range(m-1,-1,-1) range m-1 m 1 -1 -1 if cs[a[i]]==mn:
        mni = a[i]
        break
#k = (n+mn-1)//mn
#k = (n)//mn
#ddprint(f"mn {mn} mni {mni}")
#ddprint(a) cs[a[i]]==mn cs[a[i]] cs a[i] a i mn mni = a[i] mni a[i] a i break print(foo(n,0)) print foo(n,0) foo n 0 BIG = 999999999 999999999 BIG DEPMAX = 5 5 DEPMAX a = inl() inl() a cs = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] cs inn = lambda : int(input()) lambda : int(input()) inn ins = lambda : input().strip() lambda : input().strip() ins inl   = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) inl R = 10**9 + 7 10**9 + 7 R printn = lambda x: stdout.write(str(x)) lambda x: stdout.write(str(x)) printn mn = min([cs[x] for x in a]) min([cs[x] for x in a]) mn def ddprint(x):
  if DBG:
    print(x) def ddprint(x):
  if DBG:
    print(x) ddprint n,m = inm() inm() n inm   = lambda:      map(int, input().split()) lambda:      map(int, input().split()) inm def foo(n,dep):
    if dep>DEPMAX or n<0:
        ret = "-1"
    elif n==0:
        ret = ""
    elif n%mn==0:
        ret = str(mni)*(n//mn)
    else:
        mxs = "-1"
        for x in a:
            v = foo(n-cs[x],dep+1)
            if v=="-1":
                continue
            vv = v+str(x)
            if int(vv)>int(mxs):
                mxs = vv
            vv = str(x)+v
            if int(vv)>int(mxs):
                mxs = vv
        ret = mxs
    #ddprint(f"foo n {n} k {k} ret {ret}")
    return ret def foo(n,dep):
    if dep>DEPMAX or n<0:
        ret = "-1"
    elif n==0:
        ret = ""
    elif n%mn==0:
        ret = str(mni)*(n//mn)
    else:
        mxs = "-1"
        for x in a:
            v = foo(n-cs[x],dep+1)
            if v=="-1":
                continue
            vv = v+str(x)
            if int(vv)>int(mxs):
                mxs = vv
            vv = str(x)+v
            if int(vv)>int(mxs):
                mxs = vv
        ret = mxs
    #ddprint(f"foo n {n} k {k} ret {ret}")
    return ret foo m = inm() inm() m mni = a[i] a[i] mni DBG = True True DBG
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

DEPMAX = 5

def foo(n,dep):
    if dep>DEPMAX or n<0:
        ret = "-1"
    elif n==0:
        ret = ""
    elif n%mn==0:
        ret = str(mni)*(n//mn)
    else:
        mxs = "-1"
        for x in a:
            v = foo(n-cs[x],dep+1)
            if v=="-1":
                continue
            vv = v+str(x)
            if int(vv)>int(mxs):
                mxs = vv
            vv = str(x)+v
            if int(vv)>int(mxs):
                mxs = vv
        ret = mxs
    #ddprint(f"foo n {n} k {k} ret {ret}")
    return ret

n,m = inm()
a = inl()
a.sort()
cs = [0,2,5,5,4,5,6,3,7,6]
mn = min([cs[x] for x in a])
for i in range(m-1,-1,-1):
    if cs[a[i]]==mn:
        mni = a[i]
        break
#k = (n+mn-1)//mn
#k = (n)//mn
#ddprint(f"mn {mn} mni {mni}")
#ddprint(a)
print(foo(n,0))
