#include<bits/stdc++.h>
using namespace std;

string dp[(1024*1024)+5];
int kolejna[(1024*1024)+5][10];
int ile[10];

int main()
{
    int n,x;
    string slo,slo1;
    cin >> n >> slo;
    for(int i = 0;i < 1024*1024;++i)
    {
        bitset<20> maska(i);
        bitset<20> maska1(i);
        for(int j = 0;j <= 9;++j)
        {
            kolejna[(int)maska.to_ullong()][j] = (int)maska.to_ullong() | maska1.to_ullong();
            if(maska1[n-1])
            {
                maska1[n-1] = 0;
                maska1 <<= 1;
                maska1[0] = 1;
            }
            else
            {
                maska1 <<= 1;
            }
        }
    }
    for(int i = 1;i < 10;++i)
    {
        kolejna[0][i] = (1 << i);
    }
    for(int i = 0;i < (int)slo.size();++i)
    {
        ile[slo[i]-'0']++;
        if(ile[slo[i]-'0'] <= 20)
        {
            slo1 += slo[i];
        }
    }
    int wyn = -1,maks = -1;
    //bitset<20> tak(kolejna[94][5]);
    //cout << tak;
    for(int i = 0;i < (int)slo1.size();++i)
    {
        x = slo1[i]-'0';
        //cout << x;
        for(int j = (1 << n)-1;j >= 0;--j)
        {
            bitset<20> obc(j);
            bitset<20> kolj(kolejna[j][x]);
            kolj = kolj|obc;
            if(kolj[0]) continue;
            //cout << kolj << endl;
            if(dp[j].size()+1 > dp[kolj.to_ullong()].size())
            {
                dp[kolj.to_ullong()] = dp[j];
                dp[kolj.to_ullong()] += slo[i];
                if(((int)dp[kolj.to_ullong()].size() > maks) && (!kolj[0]))
                {
                    wyn = kolj.to_ullong();
                    maks = dp[kolj.to_ullong()].size();
                }
            }
        }
    }
    cout << maks << endl << dp[wyn];
}