#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,m,*a=map(int,open(0).read().split())\n"
"d=[0]+[-1]*n*9\n"
"for i in range(n):d[i+1]=max(j+d[i-int('0144345265'[j])]*10for j in a)\n"
"print(d[n])\n"
"\"";
  system(s);
  return 0;
}            