#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll n,m,a[10],b[10],d[10],k,t,s,p,h[10],q,u;
  u=5;
  cin >> n >> m;
  rep(i,m)cin >> a[i];
  q=0;
  b[1]=2;
  b[2]=5;
  b[3]=5;
  b[4]=4;
  b[5]=5;
  b[6]=6;
  b[7]=3;
  b[8]=7;
  b[9]=6;
  sort(a,a+m);
  rep(i,m)d[i]=b[a[i]];
  sort(d,d+m);
  if(n%d[0]==0){per(i,m)if(b[a[i]]==d[0]){t=a[i];
                                          break;
                                         }
                rep(i,n/d[0])printf("%lld",t);
                return 0;
               }
  else{
    per(i,m)if(b[a[i]]==d[0]){t=a[i];
                              break;
                             }
    k=n/d[0];
    s=min(k,u);
    p=n-(k-s)*d[0];
    if(s==1){
      per(i,m){if(b[a[i]]==p){h[0]=a[i];
                              q=1;
                              break;
                             }
              }
      if(q==0)goto A;
      if(h[0]>t)printf("%lld",h[0]);
      rep(i,k-1)printf("%lld",t);
      if(h[0]<=t)printf("%lld",h[0]);
      return 0;
    }
    A:;
    if(s==2){
      per(i,m){
        per(j,m){if(b[a[i]]+b[a[j]]==p){h[1]=a[j];
                                        h[0]=a[i];
                                        q=1;
                                        
                                        goto BB;
                                       }
                }
      }
      BB:;
      if(q==0)goto B;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    B:;
    if(s==3){
      per(i,m){
        per(j,m){
          per(d,m){if(b[a[i]]+b[a[j]]+b[a[d]]==p){h[2]=a[d];
                                                  h[1]=a[j];
                                                  h[0]=a[i];
                                                  q=1;
                                                  
                                                  goto CC;
                                                 }
                  }
        }
      }
      CC:;
      if(q==0)goto C;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    C:;
    if(s==4){
      per(i,m){
        per(j,m){
          per(d,m){
            per(f,m){if(b[a[i]]+b[a[j]]+b[a[d]]+b[a[f]]==p){h[3]=a[f];
                                                    h[2]=a[d];
                                                    h[1]=a[j];
                                                    h[0]=a[i];
                                                            
                                                    q=1;
                                                            goto DD;
                                                   }
                    }
          }
        }
      }
      DD:;
      if(q==0)goto D;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    D:;
    if(s==5){
      per(i,m){
        per(j,m){
          per(d,m){
            per(f,m){
              per(g,m){if(b[a[i]]+b[a[j]]+b[a[d]]+b[a[f]]+b[a[g]]==p){h[4]=a[g];
                                                    h[3]=a[f];
                                                    h[2]=a[d];
                                                    h[1]=a[j];
                                                                      h[0]=a[i];
                                                    q=1;
                                                    goto EE;
                                                   }
                    }
          }
        }
        }
      }
      EE:;
      if(q==0)goto E;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    E:; 
      k--;
      s=min(k,u);
    p=n-(k-s)*d[0];
      if(s==1){
      per(i,m){if(b[a[i]]==p){h[0]=a[i];
                              q=1;
                              goto FF;
                             }
              }
        FF:;
      if(q==0)goto F;
      if(h[0]>t)printf("%lld",h[0]);
      rep(i,k-1)printf("%lld",t);
      if(h[0]<=t)printf("%lld",h[0]);
      return 0;
    }
      F:;
      if(s==2){
      per(i,m){
        per(j,m){if(b[a[i]]+b[a[j]]==p){h[1]=a[j];
                                        h[0]=a[i];
                                        q=1;
                                        goto GG;
                                       }
                }
      }
        GG:;
      if(q==0)goto G;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    G:;
    if(s==3){
      per(i,m){
        per(j,m){
          per(d,m){if(b[a[i]]+b[a[j]]+b[a[d]]==p){h[2]=a[d];
                                                  h[1]=a[j];
                                                  h[0]=a[i];
                                                  q=1;
                                                 goto HH;
                                                 }
                  }
        }
      }
      HH:;
      if(q==0)goto H;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    H:;
    if(s==4){
      per(i,m){
        per(j,m){
          per(d,m){
            per(f,m){if(b[a[i]]+b[a[j]]+b[a[d]]+b[a[f]]==p){h[3]=a[f];
                                                    h[2]=a[d];
                                                    h[1]=a[j];
                                                    h[0]=a[i];
                                                    q=1;
                                                    goto II;
                                                   }
                    }
          }
        }
      }
      II:;
      if(q==0)goto I;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    I:;
    if(s==5){
      per(i,m){
        per(j,m){
          per(d,m){
            per(f,m){
              per(g,m){if(b[a[i]]+b[a[j]]+b[a[d]]+b[a[f]]+b[a[g]]==p){h[4]=a[g];
                                                    h[3]=a[f];
                                                    h[2]=a[d];
                                                    h[1]=a[j];
                                                                      h[0]=a[i];
                                                    q=1;
                                                    goto JJ;
                                                   }
                    }
          }
        }
        }
        }
      JJ:;
      if(q==0)goto J;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    J:; 
      k--;
      s=min(k,u);
    p=n-(k-s)*d[0];
      if(s==1){
      per(i,m){if(b[a[i]]==p){h[0]=a[i];
                              q=1;
                              goto KK;
                             }
              }
        KK:;
      if(q==0)goto K;
      if(h[0]>t)printf("%lld",h[0]);
      rep(i,k-1)printf("%lld",t);
      if(h[0]<=t)printf("%lld",h[0]);
      return 0;
    }
      K:;
      if(s==2){
      per(i,m){
        per(j,m){if(b[a[i]]+b[a[j]]==p){h[1]=a[j];
                                        h[0]=a[i];
                                        q=1;
                                        goto LL;
                                       }
                }
      }
        LL:;
      if(q==0)goto L;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    L:;
    if(s==3){
      per(i,m){
        per(j,m){
          per(d,m){if(b[a[i]]+b[a[j]]+b[a[d]]==p){h[2]=a[d];
                                                  h[1]=a[j];
                                                  h[0]=a[i];
                                                  q=1;
                                                  goto MM;
                                                 }
                  }
        }
      }
      MM:;
      if(q==0)goto M;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    M:;
    if(s==4){
      per(i,m){
        per(j,m){
          per(d,m){
            per(f,m){if(b[a[i]]+b[a[j]]+b[a[d]]+b[a[f]]==p){h[3]=a[f];
                                                    h[2]=a[d];
                                                    h[1]=a[j];
                                                    h[0]=a[i];
                                                    q=1;
                                                    goto NN;
                                                   }
                    }
          }
        }
      }

    NN:;
      if(q==0)goto N;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    N:;
    if(s==5){
      per(i,m){
        per(j,m){
          per(d,m){
            per(f,m){
              per(g,m){if(b[a[i]]+b[a[j]]+b[a[d]]+b[a[f]]+b[a[g]]==p){h[4]=a[g];
                                                    h[3]=a[f];
                                                    h[2]=a[d];
                                                    h[1]=a[j];
                                                                      h[0]=a[i];
                                                    q=1;
                                                    goto OO;
                                                   }
                    }
          }
        }
      }
              }
        OO:;
      if(q==0)goto O;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    O:;
      k--;
      s=min(k,u);
    p=n-(k-s)*d[0];
      if(s==1){
      per(i,m){if(b[a[i]]==p){h[0]=a[i];
                              q=1;
                              goto PP;
                             }
              }
        PP:;
      if(q==0)goto P;
      if(h[0]>t)printf("%lld",h[0]);
      rep(i,k-1)printf("%lld",t);
      if(h[0]<=t)printf("%lld",h[0]);
      return 0;
    }
      P:;
      if(s==2){
      per(i,m){
        per(j,m){if(b[a[i]]+b[a[j]]==p){h[1]=a[j];
                                        h[0]=a[i];
                                        q=1;
                                        goto QQ;
                                       }
                }
      }
        QQ:;
      if(q==0)goto Q;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    Q:;
    if(s==3){
      per(i,m){
        per(j,m){
          per(d,m){if(b[a[i]]+b[a[j]]+b[a[d]]==p){h[2]=a[d];
                                                  h[1]=a[j];
                                                  h[0]=a[i];
                                                  q=1;
                                                  goto RR;
                                                 }
                  }
        }
      }
      RR:;
      if(q==0)goto R;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    R:;
    if(s==4){
      per(i,m){
        per(j,m){
          per(d,m){
            per(f,m){if(b[a[i]]+b[a[j]]+b[a[d]]+b[a[f]]==p){h[3]=a[f];
                                                    h[2]=a[d];
                                                    h[1]=a[j];
                                                    h[0]=a[i];
                                                    q=1;
                                                    goto SS;
                                                   }
                    }
          }
        }
      }
      
    SS:;
      if(q==0)goto S;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    S:;
    if(s==5){
      per(i,m){
        per(j,m){
          per(d,m){
            per(f,m){
              per(g,m){if(b[a[i]]+b[a[j]]+b[a[d]]+b[a[f]]+b[a[g]]==p){h[4]=a[g];
                                                    h[3]=a[f];
                                                    h[2]=a[d];
                                                    h[1]=a[j];
                                                                      h[0]=a[i];
                                                    q=1;
                                                    goto TT;
                                                   }
                    }
          }
        }
        }
      }
      TT:;
      if(q==0)goto T;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    T:;
    k--;
      s=min(k,u);
    p=n-(k-s)*d[0];
      if(s==1){
      per(i,m){if(b[a[i]]==p){h[0]=a[i];
                              q=1;
                              goto UU;
                             }
              }
        UU:;
      if(q==0)goto U;
      if(h[0]>t)printf("%lld",h[0]);
      rep(i,k-1)printf("%lld",t);
      if(h[0]<=t)printf("%lld",h[0]);
      return 0;
    }
      U:;
      if(s==2){
      per(i,m){
        per(j,m){if(b[a[i]]+b[a[j]]==p){h[1]=a[j];
                                        h[0]=a[i];
                                        q=1;
                                        goto VV;
                                       }
                }
      }
        VV:;
      if(q==0)goto V;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    V:;
    if(s==3){
      per(i,m){
        per(j,m){
          per(d,m){if(b[a[i]]+b[a[j]]+b[a[d]]==p){h[2]=a[d];
                                                  h[1]=a[j];
                                                  h[0]=a[i];
                                                  q=1;
                                                  goto WW;
                                                 }
                  }
        }
      }
      WW:;
      if(q==0)goto W;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    W:;
    if(s==4){
      per(i,m){
        per(j,m){
          per(d,m){
            per(f,m){if(b[a[i]]+b[a[j]]+b[a[d]]+b[a[f]]==p){h[3]=a[f];
                                                    h[2]=a[d];
                                                    h[1]=a[j];
                                                    h[0]=a[i];
                                                    q=1;
                                                    goto XX;
                                                   }
                    }
          }
        }
      }
      
    XX:;
      if(q==0)goto X;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    X:;
    if(s==5){
      per(i,m){
        per(j,m){
          per(d,m){
            per(f,m){
              per(g,m){if(b[a[i]]+b[a[j]]+b[a[d]]+b[a[f]]+b[a[g]]==p){h[4]=a[g];
                                                    h[3]=a[f];
                                                    h[2]=a[d];
                                                    h[1]=a[j];
                                                                      h[0]=a[i];
                                                    q=1;
                                                    goto YY;
                                                   }
                    }
          }
        }
        }
      }
      YY:;
      if(q==0)goto Y;
      rep(i,s)if(h[i]>t)printf("%lld",h[i]);
      rep(i,k-s)printf("%lld",t);
      rep(i,s)if(h[i]<=t)printf("%lld",h[i]);
      return 0;
    }
    Y:;
    }
}

Measured memory_bytes: 256