#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];
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cmluZyBkcFsoMTAyNCoxMDI0KSs1XTsKaW50IGtvbGVqbmFbKDEwMjQqMTAyNCkrNV1bMTBdOwppbnQgaWxlWzEwXTsKCmludCBtYWluKCkKewogICAgaW50IG4seDsKICAgIHN0cmluZyBzbG8sc2xvMTsKICAgIGNpbiA+PiBuID4+IHNsbzsKICAgIGZvcihpbnQgaSA9IDA7aSA8IDEwMjQqMTAyNDsrK2kpCiAgICB7CiAgICAgICAgYml0c2V0PDIwPiBtYXNrYShpKTsKICAgICAgICBiaXRzZXQ8MjA+IG1hc2thMShpKTsKICAgICAgICBmb3IoaW50IGogPSAwO2ogPD0gOTsrK2opCiAgICAgICAgewogICAgICAgICAgICBrb2xlam5hWyhpbnQpbWFza2EudG9fdWxsb25nKCldW2pdID0gKGludCltYXNrYS50b191bGxvbmcoKSB8IG1hc2thMS50b191bGxvbmcoKTsKICAgICAgICAgICAgaWYobWFza2ExW24tMV0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIG1hc2thMVtuLTFdID0gMDsKICAgICAgICAgICAgICAgIG1hc2thMSA8PD0gMTsKICAgICAgICAgICAgICAgIG1hc2thMVswXSA9IDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBtYXNrYTEgPDw9IDE7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBmb3IoaW50IGkgPSAxO2kgPCAxMDsrK2kpCiAgICB7CiAgICAgICAga29sZWpuYVswXVtpXSA9ICgxIDw8IGkpOwogICAgfQogICAgZm9yKGludCBpID0gMDtpIDwgKGludClzbG8uc2l6ZSgpOysraSkKICAgIHsKICAgICAgICBpbGVbc2xvW2ldLScwJ10rKzsKICAgICAgICBpZihpbGVbc2xvW2ldLScwJ10gPD0gMjApCiAgICAgICAgewogICAgICAgICAgICBzbG8xICs9IHNsb1tpXTsKICAgICAgICB9CiAgICB9CiAgICBpbnQgd3luID0gLTEsbWFrcyA9IC0xOwogICAgLy9iaXRzZXQ8MjA+IHRhayhrb2xlam5hWzk0XVs1XSk7CiAgICAvL2NvdXQgPDwgdGFrOwogICAgZm9yKGludCBpID0gMDtpIDwgKGludClzbG8xLnNpemUoKTsrK2kpCiAgICB7CiAgICAgICAgeCA9IHNsbzFbaV0tJzAnOwogICAgICAgIC8vY291dCA8PCB4OwogICAgICAgIGZvcihpbnQgaiA9ICgxIDw8IG4pLTE7aiA+PSAwOy0taikKICAgICAgICB7CiAgICAgICAgICAgIGJpdHNldDwyMD4gb2JjKGopOwogICAgICAgICAgICBiaXRzZXQ8MjA+IGtvbGooa29sZWpuYVtqXVt4XSk7CiAgICAgICAgICAgIGtvbGogPSBrb2xqfG9iYzsKICAgICAgICAgICAgaWYoa29salswXSkgY29udGludWU7CiAgICAgICAgICAgIC8vY291dCA8PCBrb2xqIDw8IGVuZGw7CiAgICAgICAgICAgIGlmKGRwW2pdLnNpemUoKSsxID4gZHBba29sai50b191bGxvbmcoKV0uc2l6ZSgpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBkcFtrb2xqLnRvX3VsbG9uZygpXSA9IGRwW2pdOwogICAgICAgICAgICAgICAgZHBba29sai50b191bGxvbmcoKV0gKz0gc2xvW2ldOwogICAgICAgICAgICAgICAgaWYoKChpbnQpZHBba29sai50b191bGxvbmcoKV0uc2l6ZSgpID4gbWFrcykgJiYgKCFrb2xqWzBdKSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICB3eW4gPSBrb2xqLnRvX3VsbG9uZygpOwogICAgICAgICAgICAgICAgICAgIG1ha3MgPSBkcFtrb2xqLnRvX3VsbG9uZygpXS5zaXplKCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IG1ha3MgPDwgZW5kbCA8PCBkcFt3eW5dOwp9