using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramD a = new ProgramD();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int sound = int.Parse(s[1]) / int.Parse(s[0]);

            if (sound < int.Parse(s[2]))
                Console.WriteLine(sound);
            else
                Console.WriteLine(int.Parse(s[2]));

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int k = int.Parse(s[2]);

            int count = 0;

            for (int i = 100; i > 0; i--)
            {
                if (a % i == 0 && b % i == 0)
                    count++;

                if (count == k)
                {
                    Console.WriteLine(i);
                    return;
                }


            }
        }

        
    }

    class ProgramC
    {
        public void main()
        {

            //入力（decimal型だと桁精度が27桁ぐらいまである
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            long temp = gcd(long.Parse(s[0]), long.Parse(s[1]));
           
            for(int i = 2;i < s.Length;i++)
            {
                temp = gcd(temp, long.Parse(s[i]));
                
            }

            Console.WriteLine(temp);

        }

        /*最大公約数を求める関数*/
        static long gcd(long p, long q)
        {
            if (p < q)
            {
                long temp = p;
                p = q;
                q = temp;
            }

            long r = 1;

            while (r != 0)
            {
                r = p % q;
                p = q;
                q = r;
            }

            return p;
        }
    }



    class ProgramD
    {
        public void main()
        {

            //入力
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long m = long.Parse(s[1]);
            string[] t = Console.ReadLine().Split(' ');
            int[] num = {2,5,5,4,5,6,3,7,6};
            int[] dp = new int[n + 1];
            int INF = -10000000;

            //動的計画で最大桁数を出す
            for (int i = 1; i <= n; i++)
                dp[i] = INF;

            dp[0] = 0;
            for (int i = 0;i <= n;i++)
            {
                if (dp[i] == INF)
                    continue;
                for (int j = 0; j < m; j++)

                {
                    if(i + num[int.Parse(t[j])- 1] <= n)
                        dp[i + num[int.Parse(t[j]) - 1]] = Math.Max(dp[i + num[int.Parse(t[j]) - 1]], dp[i] + 1);
                }
            }

            int pos = (int)n;
            //答え出力
            for(int i = 0;i < dp[n];i++)
            {

                int max = 0;
                int sub = 0;

                for (int j = 0; j < m; j++)
                {
                    if (pos - num[int.Parse(t[j]) - 1] >= 0)
                    {
                        if (dp[pos - num[int.Parse(t[j]) - 1]] == dp[pos] - 1)
                        {
                            if (max < int.Parse(t[j]))
                            {
                                max = int.Parse(t[j]);
                                sub = num[int.Parse(t[j]) - 1];
                            }
                        }
                    }
                }

                Console.Write(max);
                pos -= sub;

            }

        }
    }

   
}






Measured memory_bytes: 13140