#include <bits/stdc++.h>
using namespace std;
int cnt[10]={0,2,5,5,4,5,6,3,7,6};
bool can[10];
int dp[10002];
int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  memset(dp,-1,sizeof(dp));
  dp[0]=0;
  while(m--){
    int x;
    scanf("%d",&x);
    can[x]=1;
    for(int i=cnt[x];i<=n;i++)
      dp[i]=max(dp[i],dp[i-cnt[x]]+1);
  }
  int now=n;
  while(now){
    for(int i=9;i;i--)
      if (can[i] && now>=cnt[i] && dp[now-cnt[i]]==dp[now]-1){
        putchar(i+'0'),now-=cnt[i];
        break;
      }
  }
}