#include<bits/stdc++.h>
using namespace std;
int main()
{
     long int n;
     cin>>n;
     long int a[n];
     cin>>a[0];
     bool flag=false;
     set<long int> s;
     s.insert(a[0]);
     for(long int i=1;i<n;i++)
      {    cin>>a[i];

        if(!flag && s.find(a[i]-1)!=s.end())
        {
            flag=true;
        }
        s.insert(a[i]);

      }
      if(!flag)
      {
          cout<<"1"<<endl;
          cout<<a[0];
          return 0;
      }

     long  int dp[n];
     for(long int i=0;i<n;i++)
          dp[i]=1;

     for(long int i=1;i<n;i++)
     {
          for(long int j=i-1;j>=0;j--)
          {
               if(a[j]+1 == a[i] && dp[j]+1 > dp[i] )
               {
                    dp[i]=dp[j]+1;
                    break;
               }
          }
     }
     long int ind=-1;
     long int lis=INT_MIN;
     for(long int i=0; i<n;i++)
     {
          if(dp[i]>lis)
          {
               lis=dp[i];
               ind=i;
          }
     }
 cout<<lis<<endl;
 //for(int i=0;i<n;i++)
   // cout<<dp[i]<<" ";
    //cout<<endl;
     stack<long int> s;
     while(ind >= 0)
     {
      //cout<<a[ind]<<endl;
          s.push(ind+1);
          long int j=ind;
          while(j>=0) //if(dp[ind]-1 !=dp[j] && a[j] != a[ind]-1)
          {
              if((dp[j]==dp[ind]-1 ) && (a[j] == a[ind]-1))
               break;
               j--;
          }
          ind=j;
     }
     while(!s.empty())
     {
          cout<<s.top()<<" ";
          s.pop();
     }
     return 0;
}


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

#define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define  ll             int
#define  pb             push_back
#define  all(v)         v.begin(),v.end()
vector<int>v2[200005],v3[200005];
vector<ll>v1;
bool vis[200005];
unordered_map<ll,int>mp;
int main()
{
    CIN;
    ll  a,b,c,d,n,e,f,i,j,val=0,indx=0,mx=0,idx;

    cin >> n ;
    for( i =0 ; i < n ; i++)
    {
        cin >> a ;
        v1.pb(a);
        if(mp[a]==0) mp[a]=++val;
        v2[mp[a]].pb(i);
    }
    for( i = 0 ; i < n ; i++)
    {
        if(!vis[i])
        {
            v3[indx].pb(i+1);
            vis[i]=1;
            ll last = i ;
            for( j = v1[i]+1 ; ;j++)
            {
                if(!mp.count(j)) break;
                ll id = mp[j];
                ll x = lower_bound(all(v2[id]),last)-v2[id].begin();
                if(x<v2[id].size()){
                    last = v2[id][x];
                    v3[indx].pb(last+1);
                    vis[last]=1;
                }
                else break;
            }
            if(v3[indx].size()>mx)
            {
                idx = indx ;
                mx = v3[indx].size();
            }
            indx++;
        }
    }
    cout<<mx<<endl;
    for( i = 0 ; i < mx ; i++) cout<<v3[idx][i]<<" ";
    return 0 ;
}


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

#define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define  ll             int
#define  pb             push_back
#define  all(v)         v.begin(),v.end()
vector<int>v2[200005];
vector<ll>v1;
bool vis[200005];
unordered_map<ll,int>mp;
int main()
{
    CIN;
    ll  a,b,c,d,n,e,f,i,j,val=0,mx=0,idx;

    cin >> n ;
    for( i =0 ; i < n ; i++)
    {
        cin >> a ;
        v1.pb(a);
        if(mp[a]==0)
            mp[a]=++val;
        v2[mp[a]].pb(i);
    }
    for( i = 0 ; i < n ; i++)
    {
        if(!vis[i])
        {
            vis[i]=1;
            ll last = i, cnt=1 ;
            for( j = v1[i]+1 ; ; j++)
            {
                if(!mp.count(j))
                    break;
                ll id = mp[j];
                ll x = lower_bound(all(v2[id]),last)-v2[id].begin();
                if(x<v2[id].size())
                {
                    last = v2[id][x];
                    vis[last]=1;
                }
                else
                    break;
            }
            if(cnt>mx)
            {
                idx = i ;
                mx = cnt;
            }
        }
    }
    cout<<mx<<endl;
    i = idx ;
    cout<<i+1<<" ";
    ll last = i ;
    for( j = v1[i]+1 ; ; j++)
    {
        if(!mp.count(j))
            break;
        ll id = mp[j];
        ll x = lower_bound(all(v2[id]),last)-v2[id].begin();
        if(x<v2[id].size())
        {
            last = v2[id][x];
            cout<<last+1<<" ";
        }
        else
            break;
    }
    return 0 ;
}


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

#define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define  ll             long long int
#define  pb             push_back
#define  all(v)         v.begin(),v.end()
vector<ll>v1,v2[200005],v3[200005];
bool vis[200005];
map<ll,ll>mp;
int main()
{
    CIN;
    ll  a,b,c,d,n,e,f,i,j,val=0,indx=0,mx=0,idx;

    cin >> n ;
    for( i =0 ; i < n ; i++)
    {
        cin >> a ;
        v1.pb(a);
        if(mp[a]==0) mp[a]=++val;
        v2[mp[a]].pb(i);
    }
    for( i = 0 ; i < n ; i++)
    {
        ll p = mp[v1[i]];
        if(!vis[p])
        {
            v3[indx].pb(i+1);
            vis[p]=1;
            ll last = i , cnt = 1;
            for( j = v1[i]+1 ; ;j++)
            {
                if(!mp.count(j)) break;
                ll id = mp[j];
                ll x = lower_bound(all(v2[id]),last)-v2[id].begin();
                if(x<v2[id].size()){
                    last = v2[id][x];
                    v3[indx].pb(last+1);
                    vis[id]=1;
                }
                else break;
            }
            if(v3[indx].size()>mx)
            {
                idx = indx ;
                mx = v3[indx].size();
            }
            indx++;
        }
    }
    cout<<mx<<endl;
    for( i = 0 ; i < mx ; i++) cout<<v3[idx][i]<<" ";
    return 0 ;
}


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

#define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define  ll             long long int
#define  pb             push_back
#define  all(v)         v.begin(),v.end()
vector<ll>v1,v2[200005],v3[200005];
bool vis[200005];
map<ll,ll>mp;
int main()
{
    CIN;
    ll  a,b,c,d,n,e,f,i,j,val=0,indx=0,mx=0,idx;

    cin >> n ;
    for( i =0 ; i < n ; i++)
    {
        cin >> a ;
        v1.pb(a);
        if(mp[a]==0) mp[a]=++val;
        v2[mp[a]].pb(i);
    }
    for( i = 0 ; i < n ; i++)
    {
        ll p = mp[v1[i]];
        if(!vis[p])
        {
            v3[indx].pb(i+1);
            vis[i]=1;
            ll last = i , cnt = 1;
            for( j = v1[i]+1 ; ;j++)
            {
                if(!mp.count(j)) break;
                ll id = mp[j];
                ll x = lower_bound(all(v2[id]),last)-v2[id].begin();
                if(x<v2[id].size()){
                    last = v2[id][x];
                    v3[indx].pb(last+1);
                    vis[last]=1;
                }
                else break;
            }
            if(v3[indx].size()>mx)
            {
                idx = indx ;
                mx = v3[indx].size();
            }
            indx++;
        }
    }
    cout<<mx<<endl;
    for( i = 0 ; i < mx ; i++) cout<<v3[idx][i]<<" ";
    return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define  ll    int

map<ll,ll>mp;
vector<ll>v1,v2;
int main()
{
    CIN;
    ll  a,i,n,mx=0,id;

    cin >> n ;
    for( i =0 ; i < n ; i++)
    {
        cin >> a ;
        v1.push_back(a);
        mp[a]=mp[a-1]+1;
    }
    for( i = 0 ; i < n ; i++)
    {
        if(mp[v1[i]]>mx)
        {
            mx=mp[v1[i]];
            id=v1[i];
        }
    }
    cout<<mx<<endl;
    for( i = n-1 ; i>=0 ; i--)
    {
        if(v1[i]==id){
            v2.push_back(i+1);
            id--;
        }
    }
    while(v2.size())
    {
        cout<<v2.back()<<" ";
        v2.pop_back();
    }
    return 0 ;
}


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

#define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define  ll             int
#define  pb             push_back
#define  all(v)         v.begin(),v.end()
vector<int>v2[200005];
vector<ll>v1;
bool vis[200005];
unordered_map<ll,int>mp;
int main()
{
    CIN;
    ll  a,b,c,d,n,e,f,i,j,val=0,mx=0,idx;

    cin >> n ;
    for( i =0 ; i < n ; i++)
    {
        cin >> a ;
        v1.pb(a);
        if(mp[a]==0)
            mp[a]=++val;
        v2[mp[a]].pb(i);
    }
    for( i = 0 ; i < n ; i++)
    {
        if(!vis[i])
        {
            vis[i]=1;
            ll last = i, cnt=1 ;
            for( j = v1[i]+1 ; ; j++)
            {
                if(!mp.count(j))
                    break;
                ll id = mp[j];
                ll x = lower_bound(all(v2[id]),last)-v2[id].begin();
                if(x<v2[id].size())
                {
                    last = v2[id][x];
                    vis[last]=1;
                    cnt++;
                }
                else
                    break;
            }
            if(cnt>mx)
            {
                idx = i ;
                mx = cnt;
            }
        }
    }
    cout<<mx<<endl;
    i = idx ;
    cout<<i+1<<" ";
    ll last = i ;
    for( j = v1[i]+1 ; ; j++)
    {
        if(!mp.count(j))
            break;
        ll id = mp[j];
        ll x = lower_bound(all(v2[id]),last)-v2[id].begin();
        if(x<v2[id].size())
        {
            last = v2[id][x];
            cout<<last+1<<" ";
        }
        else
            break;
    }
    return 0 ;
}


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

#define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define  ll             long long int
#define  pb             push_back
#define  all(v)         v.begin(),v.end()
vector<int>v2[200005],v3[200005];
vector<ll>v1;
bool vis[200005];
unordered_map<ll,int>mp;
int main()
{
    CIN;
    ll  a,b,c,d,n,e,f,i,j,val=0,indx=0,mx=0,idx;

    cin >> n ;
    for( i =0 ; i < n ; i++)
    {
        cin >> a ;
        v1.pb(a);
        if(mp[a]==0) mp[a]=++val;
        v2[mp[a]].pb(i);
    }
    for( i = 0 ; i < n ; i++)
    {
        if(!vis[i])
        {
            v3[indx].pb(i+1);
            vis[i]=1;
            ll last = i ;
            for( j = v1[i]+1 ; ;j++)
            {
                if(!mp.count(j)) break;
                ll id = mp[j];
                ll x = lower_bound(all(v2[id]),last)-v2[id].begin();
                if(x<v2[id].size()){
                    last = v2[id][x];
                    v3[indx].pb(last+1);
                    vis[last]=1;
                }
                else break;
            }
            if(v3[indx].size()>mx)
            {
                idx = indx ;
                mx = v3[indx].size();
            }
            indx++;
        }
    }
    cout<<mx<<endl;
    for( i = 0 ; i < mx ; i++) cout<<v3[idx][i]<<" ";
    return 0 ;
}


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

#define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define  ll             long long int
#define  pb             push_back
#define  all(v)         v.begin(),v.end()
vector<ll>v1,v2[200005],v3[200005];
bool vis[200005];
unordered_map<ll,ll>mp;
int main()
{
    CIN;
    ll  a,b,c,d,n,e,f,i,j,val=0,indx=0,mx=0,idx;

    cin >> n ;
    for( i =0 ; i < n ; i++)
    {
        cin >> a ;
        v1.pb(a);
        if(mp[a]==0) mp[a]=++val;
        v2[mp[a]].pb(i);
    }
    for( i = 0 ; i < n ; i++)
    {
        if(!vis[i])
        {
            v3[indx].pb(i+1);
            vis[i]=1;
            ll last = i ;
            for( j = v1[i]+1 ; ;j++)
            {
                if(!mp.count(j)) break;
                ll id = mp[j];
                ll x = lower_bound(all(v2[id]),last)-v2[id].begin();
                if(x<v2[id].size()){
                    last = v2[id][x];
                    v3[indx].pb(last+1);
                    vis[last]=1;
                }
                else break;
            }
            if(v3[indx].size()>mx)
            {
                idx = indx ;
                mx = v3[indx].size();
            }
            indx++;
        }
    }
    cout<<mx<<endl;
    for( i = 0 ; i < mx ; i++) cout<<v3[idx][i]<<" ";
    return 0 ;
}


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

#define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define  ll             int
#define  pb             push_back
#define  all(v)         v.begin(),v.end()
set<int>st[200005];
int parent[200005];
vector<ll>v1;
bool vis[200005];
unordered_map<ll,int>mp;
int main()
{
    CIN;
    ll  a,b,c,d,n,e,f,i,j,val=0,indx=0,mx=0,idx;

    cin >> n ;
    for( i =0 ; i < n ; i++)
    {
        cin >> a ;
        v1.pb(a);
        if(mp[a]==0) mp[a]=++val;
        st[mp[a]].insert(i);
    }
    for( i = 0 ; i < n ; i++)
    {
        if(!vis[i])
        {
            vis[i]=1;
            ll last = i , cnt=1 ;
            parent[i]=-1;
            for( j = v1[i]+1 ; ;j++)
            {
                if(!mp.count(j)) break;
                ll id = mp[j];
                auto it = st[id].lower_bound(last);
                if(it!=st[id].end()){
                    parent[*it]=last;
                    last = *it;
                    vis[last]=1;
                    cnt++;
                    st[id].erase(it);
                }
                else break;
            }
            if(cnt>mx)
            {
                idx = last;
                mx=cnt;
            }
        }
    }
    cout<<mx<<endl;
    ll x = mx ;
    while(idx!=-1)
    {
        v1[x--] = idx;
        idx = parent[idx];
    }
    for( i = 1 ; i <= mx ; i++) cout<<v1[i]+1<<" ";
    return 0 ;
}


import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class C {

    int n,k;
    String num;
    String res;
    int minCost = 0;
    HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
    public void run(){
        Scanner s = new Scanner(new InputStreamReader(System.in));
        n = s.nextInt();
        k = s.nextInt();
        num = s.next();
        for (int i = 0; i <= 9; i++)
            map.put(i,new ArrayList<Integer>());

        for (int i = 0; i < num.length(); i++)
            map.get(num.charAt(i)-'0').add(i);

        int max = 0;
        int maxDigit = -1;
        for (int i = 0; i <= 9; i++){
            if (map.get(i).size() > max){
                max = map.get(i).size();
                maxDigit = i;
            }
        }

        res = num;
        minCost = Integer.MAX_VALUE;
        for (int i = 0; i <= 9 ; i++) {
//          if (map.get(i).size() < max) continue;
            max = map.get(i).size();
            maxDigit = i;
            if (max >= k){
                minCost = 0;
                res = num;
                break;
            }
            int toflip = k - max;
            int dist = 1;

            StringBuilder buff = new StringBuilder(num);
            int cost = 0;
            while (toflip > 0){
                int up =  maxDigit + dist;
                if (up <= 9 && map.get(up).size() > 0){
                    int x=0;
                    while (toflip > 0 && x < map.get(up).size()){
                        cost += dist;
                        buff.replace(map.get(up).get(x),map.get(up).get(x)+1 , maxDigit + "");
                        x++;
                        toflip--;
                    }
                }
                if (toflip == 0) break;
                int down =  maxDigit - dist;
                if (down >= 0 && map.get(down).size() > 0){
                    int x=0;
                    while (toflip > 0 && x < map.get(down).size()){
                        cost += dist;
                        buff.replace(map.get(down).get(x),map.get(down).get(x)+1 , maxDigit + "");
                        x++;
                        toflip--;
                    }
                }
                dist +=1;
            }
            if (cost == minCost){
                if (buff.toString().compareTo(res) < 0)
                    res = buff.toString();
            }
            if (cost < minCost){
                minCost = cost;
                res = buff.toString();
            }
        }

        System.out.println(minCost);
        System.out.println(res);
    }

    public static void main(String[] args) {
        (new C()).run();
    }

}


import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class C {

    int n,k;
    String num;
    String res;
    int minCost = 0;
    HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
    public void run(){
        Scanner s = new Scanner(new InputStreamReader(System.in));
        n = s.nextInt();
        k = s.nextInt();
        num = s.next();
        for (int i = 0; i <= 9; i++)
            map.put(i,new ArrayList<Integer>());

        for (int i = 0; i < num.length(); i++)
            map.get(num.charAt(i)-'0').add(i);

        int max = 0;
        int maxDigit = -1;
        for (int i = 0; i <= 9; i++){
            if (map.get(i).size() > max){
                max = map.get(i).size();
                maxDigit = i;
            }
        }

        res = num;
        minCost = Integer.MAX_VALUE;
        for (int i = 0; i <= 9 ; i++) {
//          if (map.get(i).size() < max) continue;
            if (max >= k){
                minCost = 0;
                res = num;
                break;
            }
            int toflip = k - max;
            int dist = 1;

            StringBuilder buff = new StringBuilder(num);
            int cost = 0;
            while (toflip > 0){
                int up =  maxDigit + dist;
                if (up <= 9 && map.get(up).size() > 0){
                    int x=0;
                    while (toflip > 0 && x < map.get(up).size()){
                        cost += dist;
                        buff.replace(map.get(up).get(x),map.get(up).get(x)+1 , maxDigit + "");
                        x++;
                        toflip--;
                    }
                }
                if (toflip == 0) break;
                int down =  maxDigit - dist;
                if (down >= 0 && map.get(down).size() > 0){
                    int x=0;
                    while (toflip > 0 && x < map.get(down).size()){
                        cost += dist;
                        buff.replace(map.get(down).get(x),map.get(down).get(x)+1 , maxDigit + "");
                        x++;
                        toflip--;
                    }
                }
                dist +=1;
            }
            if (cost == minCost){
                if (buff.toString().compareTo(res) < 0)
                    res = buff.toString();
            }
            if (cost < minCost){
                minCost = cost;
                res = buff.toString();
            }
        }

        System.out.println(minCost);
        System.out.println(res);
    }

    public static void main(String[] args) {
        (new C()).run();
    }

}


import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class C {

    int n,k;
    String num;
    String res;
    int minCost = 0;
    HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
    public void run(){
        Scanner s = new Scanner(new InputStreamReader(System.in));
        n = s.nextInt();
        k = s.nextInt();
        num = s.next();
        for (int i = 0; i <= 9; i++)
            map.put(i,new ArrayList<Integer>());

        for (int i = 0; i < num.length(); i++)
            map.get(num.charAt(i)-'0').add(i);

        res = num;
        minCost = Integer.MAX_VALUE;
        for (int i = 0; i <= 9 ; i++) {
            int freq = map.get(i).size();
            int digit = i;
            if (freq >= k){
                minCost = 0;
                res = num;
                break;
            }
            int toflip = k - freq;
            int dist = 1;

            StringBuilder buff = new StringBuilder(num);
            int cost = 0;
            while (toflip > 0){
                int up =  digit + dist;
                if (up <= 9 && map.get(up).size() > 0){
                    int x=0;
                    while (toflip > 0 && x < map.get(up).size()){
                        cost += dist;
                        buff.replace(map.get(up).get(x),map.get(up).get(x)+1 , digit + "");
                        toflip--;
                        x++;
                    }
                }
                if (toflip == 0) break;
                int down =  digit - dist;
                if (down >= 0 && map.get(down).size() > 0){
                    int x = map.get(down).size()-1;
                    while (toflip > 0 && x >= 0){
                        cost += dist;
                        buff.replace(map.get(down).get(x),map.get(down).get(x)+1 , digit + "");
                        toflip--;
                        x--;
                    }
                }
                dist +=1;
            }
            if (cost < minCost){
                minCost = cost;
                res = buff.toString();
            }
        }

        System.out.println(minCost);
        System.out.println(res);
    }

    public static void main(String[] args) {
        (new C()).run();
    }

}


import java.io.*;
public class Main {
    public static void main(String [] args) throws IOException {
        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        args = br.readLine().split(" ");
        int n = Integer.parseInt(args[0]);
        int k = Integer.parseInt(args[1]);
        String s = br.readLine();
        char [] data = s.toCharArray();
        int [][] digitPos = new int [10][];
        for (int i = 0; i < 10; i++) {
            int count = 0;
            for (char c : data) if (c == (char)('0' + i)) count++;
            digitPos [i] = new int [count];
            int _ = 0;
            for (int j = 0; j < data.length; j++)
                if (data[j] == (char)('0' + i))
                    digitPos[i][_++] = j;
        }
        int minCost = Integer.MAX_VALUE;
        int chosenDigit = -1;
        for (int i = 0; i <= 9; i++) {
            int remCount = k - digitPos[i].length;
            int r = i + 1, l = i - 1;
            int totalCost = 0;
            while(remCount > 0) {
                if ((r - i == i - l || l < 0) && r <= 9) {
                    totalCost += (r - i) * Math.min(remCount, digitPos[r].length);
                    remCount -= digitPos[r].length;
                    r++;
                } else {
                    totalCost += (i - l) * Math.min(remCount, digitPos[l].length);
                    remCount -= digitPos[l].length;
                    l--;
                }
            }
            if (totalCost < minCost) {minCost = totalCost; chosenDigit = i;}
        }
        int lastTaken = -1;
        int remCount = k - digitPos[chosenDigit].length;
        int r = chosenDigit  + 1, l = chosenDigit - 1;
        while(remCount > 0) {
            if (lastTaken == -1 && r <= 9) {
                for (int i = 0; i < digitPos[r].length && remCount > 0; i++) {
                    data[digitPos[r][i]] = (char)('0' + chosenDigit); remCount --;
                }
                r ++;
            } else {
                for (int i = 0; i < digitPos[l].length && remCount > 0; i++) {
                    data[digitPos[l][i]] = (char)('0' + chosenDigit); remCount --;
                }
                l --;
            }
            lastTaken *= -1;
        }
        System.out.println(minCost);
        System.out.println(new String(data));
    }
}


import java.io.*;
public class FancyNum {
    public static void main(String [] args) throws IOException {
        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        args = br.readLine().split(" ");
        int n = Integer.parseInt(args[0]);
        int k = Integer.parseInt(args[1]);
        String s = br.readLine();
        char [] data = s.toCharArray();
        int [][] digitPos = new int [10][];
        for (int i = 0; i < 10; i++) {
            int count = 0;
            for (char c : data) if (c == (char)('0' + i)) count++;
            digitPos [i] = new int [count];
            int _ = 0;
            for (int j = 0; j < data.length; j++)
                if (data[j] == (char)('0' + i))
                    digitPos[i][_++] = j;
        }
        int minCost = Integer.MAX_VALUE;
        int chosenDigit = -1;
        for (int i = 0; i <= 9; i++) {
            int remCount = k - digitPos[i].length;
            int r = i + 1, l = i - 1;
            int totalCost = 0;
            while(remCount > 0) {
                if ((r - i == i - l || l < 0) && r <= 9) {
                    totalCost += (r - i) * Math.min(remCount, digitPos[r].length);
                    remCount -= digitPos[r].length;
                    r++;
                } else {
                    totalCost += (i - l) * Math.min(remCount, digitPos[l].length);
                    remCount -= digitPos[l].length;
                    l--;
                }
            }
            if (totalCost < minCost) {minCost = totalCost; chosenDigit = i;}
        }
        int lastTaken = -1;
        int remCount = k - digitPos[chosenDigit].length;
        int r = chosenDigit  + 1, l = chosenDigit - 1;
        while(remCount > 0) {
            if ((lastTaken == -1  || l < 0)&& r <= 9) {
                for (int i = 0; i < digitPos[r].length && remCount > 0; i++) {
                    data[digitPos[r][i]] = (char)('0' + chosenDigit); remCount --;
                }
                r ++;
            } else {
                for (int i = digitPos[l].length - 1; i >= 0 && remCount > 0; i--) {
                    data[digitPos[l][i]] = (char)('0' + chosenDigit); remCount --;
                }
                l --;
            }
            lastTaken *= -1;
        }
        System.out.println(minCost);
        System.out.println(new String(data));
    }
}


import java.io.*;
import java.util.*;
public class FancyNum {
    public static void main(String [] args) throws IOException {
        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        args = br.readLine().split(" ");
        int n = Integer.parseInt(args[0]);
        int k = Integer.parseInt(args[1]);
        String s = br.readLine();
        char [] data = s.toCharArray();
        int [][] digitPos = new int [10][];
        for (int i = 0; i < 10; i++) {
            int count = 0;
            for (char c : data) if (c == (char)('0' + i)) count++;
            digitPos [i] = new int [count];
            int _ = 0;
            for (int j = 0; j < data.length; j++)
                if (data[j] == (char)('0' + i))
                    digitPos[i][_++] = j;
        }
        int minCost = Integer.MAX_VALUE;
        LinkedList<Integer> chosenDigits = new LinkedList<Integer>();
        for (int i = 0; i <= 9; i++) {
            int remCount = k - digitPos[i].length;
            int r = i + 1, l = i - 1;
            int totalCost = 0;
            while(remCount > 0) {
                if ((r - i == i - l || l < 0) && r <= 9) {
                    totalCost += (r - i) * Math.min(remCount, digitPos[r].length);
                    remCount -= digitPos[r].length;
                    r++;
                } else {
                    totalCost += (i - l) * Math.min(remCount, digitPos[l].length);
                    remCount -= digitPos[l].length;
                    l--;
                }
            }
            if (totalCost < minCost) {minCost = totalCost; chosenDigits = new LinkedList<Integer>(); chosenDigits.add(i);}
            else if (totalCost == minCost) {chosenDigits.add(i);}
        }
        PriorityQueue<String> answers = new PriorityQueue<String>();
        for (int chosenDigit : chosenDigits) {
        data = s.toCharArray();
        int lastTaken = -1;
        int remCount = k - digitPos[chosenDigit].length;
        int r = chosenDigit  + 1, l = chosenDigit - 1;
        while(remCount > 0) {
            if ((lastTaken == -1  || l < 0)&& r <= 9) {
                for (int i = 0; i < digitPos[r].length && remCount > 0; i++) {
                    data[digitPos[r][i]] = (char)('0' + chosenDigit); remCount --;
                }
                r ++;
            } else {
                for (int i = digitPos[l].length - 1; i >= 0 && remCount > 0; i--) {
                    data[digitPos[l][i]] = (char)('0' + chosenDigit); remCount --;
                }
                l --;
            }
            lastTaken *= -1;
        }
        answers.add(new String(data));
        }
        System.out.println(minCost);
        System.out.println(answers.remove());
    }
}


import java.io.*;
public class Main {
    public static void main(String [] args) throws IOException {
        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        args = br.readLine().split(" ");
        int n = Integer.parseInt(args[0]);
        int k = Integer.parseInt(args[1]);
        String s = br.readLine();
        char [] data = s.toCharArray();
        int [][] digitPos = new int [10][];
        for (int i = 0; i < 10; i++) {
            int count = 0;
            for (char c : data) if (c == (char)('0' + i)) count++;
            digitPos [i] = new int [count];
            int _ = 0;
            for (int j = 0; j < data.length; j++)
                if (data[j] == (char)('0' + i))
                    digitPos[i][_++] = j;
        }
        int minCost = Integer.MAX_VALUE;
        int chosenDigit = -1;
        for (int i = 0; i <= 9; i++) {
            int remCount = k - digitPos[i].length;
            int r = i + 1, l = i - 1;
            int totalCost = 0;
            while(remCount > 0) {
                if ((r - i == i - l || l < 0) && r <= 9) {
                    totalCost += (r - i) * Math.min(remCount, digitPos[r].length);
                    remCount -= digitPos[r].length;
                    r++;
                } else {
                    totalCost += (i - l) * Math.min(remCount, digitPos[l].length);
                    remCount -= digitPos[l].length;
                    l--;
                }
            }
            if (totalCost < minCost) {minCost = totalCost; chosenDigit = i;}
        }
        int lastTaken = -1;
        int remCount = k - digitPos[chosenDigit].length;
        int r = chosenDigit  + 1, l = chosenDigit - 1;
        while(remCount > 0) {
            if (lastTaken == -1 && r <= 9) {
                for (int i = 0; i < digitPos[r].length && remCount > 0; i++) {
                    data[digitPos[r][i]] = (char)('0' + chosenDigit); remCount --;
                }
                r ++;
            } else {
                for (int i = digitPos[l].length - 1; i >= 0 && remCount > 0; i--) {
                    data[digitPos[l][i]] = (char)('0' + chosenDigit); remCount --;
                }
                l --;
            }
            lastTaken *= -1;
        }
        System.out.println(minCost);
        System.out.println(new String(data));
    }
}


//package round89;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class C2 {
	Scanner in;
	PrintWriter out;
//	String INPUT = "6 5 898196";
//	String INPUT = "10 6 0001112223";
	String INPUT = "5 4 12221";

	void solve()
	{
		int n = ni();
		int k = ni();
		char[] s = in.next().toCharArray();
		int[] ct = new int[10];
		for(char c : s){
			ct[c-'0']++;
		}

		int opt = 0;
		long mincost = Integer.MAX_VALUE;
		int[][] us = new int[10][10];
		Integer[] ord = new Integer[10];
		for(int j = 0;j <= 9;j++)ord[j] = j;
		for(int i = 0;i <= 9;i++){
			final int ii = i;
			Arrays.sort(ord, new Comparator<Integer>(){
				public int compare(Integer a, Integer b){
					int da = Math.abs(a-ii);
					int db = Math.abs(b-ii);
					if(da != db)return da - db;
					return a - b;
				}
			});

			int left = k;
			long cost = 0;
			for(int j = 0;j <= 9 && left > 0;j++){
				int use = Math.min(left, ct[ord[j]]);
				us[i][ord[j]] = use;
				cost += Math.abs(ord[j]-i)*use;
				left -= use;
			}
			if(cost < mincost){
				mincost = cost;
				opt = 1<<i;
			}else if(cost == mincost){
				opt |= 1<<i;
			}
		}

		out.println(mincost);
		String gmin = null;
		for(int i = 0;i <= 9;i++){
			if(opt<<31-i<0){
				char[] t = Arrays.copyOf(s, s.length);
				for(int j = 0;j < t.length;j++){
					if(us[i][t[j]-'0'] > 0){
						if(t[j]-'0'<i){
							if(ct[t[j]-'0'] == us[i][t[j]-'0']){
								t[j] = (char)('0' + i);
								us[i][t[j]-'0']--;
							}
							ct[t[j]-'0']--;
						}else{
							us[i][t[j]-'0']--;
							t[j] = (char)('0' + i);
						}
					}
				}
				if(gmin == null){
					gmin = new String(t);
				}else{
					String st = new String(t);
					if(st.compareTo(gmin) < 0){
						gmin = st;
					}
				}
			}
		}
		out.println(gmin);
	}

	void run() throws Exception
	{
		in = oj ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{
		new C2().run();
	}

	int ni() { return Integer.parseInt(in.next()); }
	long nl() { return Long.parseLong(in.next()); }
	double nd() { return Double.parseDouble(in.next()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


//package round89;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class C {
	Scanner in;
	PrintWriter out;
//	String INPUT = "6 5 898196";
//	String INPUT = "10 6 0001112223";
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int k = ni();
		char[] s = in.next().toCharArray();
		int[] ct = new int[10];
		for(char c : s){
			ct[c-'0']++;
		}

		int opt = 0;
		long mincost = Integer.MAX_VALUE;
		int[][] us = new int[10][10];
		Integer[] ord = new Integer[10];
		for(int j = 0;j <= 9;j++)ord[j] = j;
		for(int i = 0;i <= 9;i++){
			final int ii = i;
			Arrays.sort(ord, new Comparator<Integer>(){
				public int compare(Integer a, Integer b){
					int da = Math.abs(a-ii);
					int db = Math.abs(b-ii);
					if(da != db)return da - db;
					return a - b;
				}
			});

			int left = k;
			long cost = 0;
			for(int j = 0;j <= 9 && left > 0;j++){
				int use = Math.min(left, ct[ord[j]]);
				us[i][ord[j]] = use;
				cost += Math.abs(ord[j]-i)*use;
				left -= use;
			}
			if(cost < mincost){
				mincost = cost;
				opt = 1<<i;
			}else if(cost == mincost){
				opt |= 1<<i;
			}
		}

		out.println(mincost);
		String gmin = null;
		for(int i = 0;i <= 9;i++){
			if(opt<<31-i<0){
				char[] t = Arrays.copyOf(s, s.length);
				for(int j = 0;j < t.length;j++){
					if(us[i][t[j]-'0'] > 0){
						us[i][t[j]-'0']--;
						t[j] = (char)('0' + i);
					}
				}
				if(gmin == null){
					gmin = new String(t);
				}else{
					String st = new String(t);
					if(st.compareTo(gmin) < 0){
						gmin = st;
					}
				}
			}
		}
		out.println(gmin);
	}

	void run() throws Exception
	{
		in = oj ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{
		new C().run();
	}

	int ni() { return Integer.parseInt(in.next()); }
	long nl() { return Long.parseLong(in.next()); }
	double nd() { return Double.parseDouble(in.next()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


//package round89;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class C2 {
	Scanner in;
	PrintWriter out;
//	String INPUT = "6 5 898196";
//	String INPUT = "10 6 0001112223";
	String INPUT = "7 5 1222211";

	void solve()
	{
		int n = ni();
		int k = ni();
		char[] s = in.next().toCharArray();
		int[] ct = new int[10];
		for(char c : s){
			ct[c-'0']++;
		}

		int opt = 0;
		long mincost = Integer.MAX_VALUE;
		int[][] us = new int[10][10];
		Integer[] ord = new Integer[10];
		for(int j = 0;j <= 9;j++)ord[j] = j;
		for(int i = 0;i <= 9;i++){
			final int ii = i;
			Arrays.sort(ord, new Comparator<Integer>(){
				public int compare(Integer a, Integer b){
					int da = Math.abs(a-ii);
					int db = Math.abs(b-ii);
					if(da != db)return da - db;
					return -(a - b);
				}
			});

			int left = k;
			long cost = 0;
			for(int j = 0;j <= 9 && left > 0;j++){
				int use = Math.min(left, ct[ord[j]]);
				us[i][ord[j]] = use;
				cost += Math.abs(ord[j]-i)*use;
				left -= use;
			}
			if(cost < mincost){
				mincost = cost;
				opt = 1<<i;
			}else if(cost == mincost){
				opt |= 1<<i;
			}
		}

		out.println(mincost);
		String gmin = null;
		for(int i = 0;i <= 9;i++){
			if(opt<<31-i<0){
				char[] t = Arrays.copyOf(s, s.length);
				for(int j = 0;j < t.length;j++){
					if(us[i][t[j]-'0'] > 0){
						if(t[j]-'0'<i){
							if(ct[t[j]-'0'] == us[i][t[j]-'0']){
								t[j] = (char)('0' + i);
								us[i][t[j]-'0']--;
							}
							ct[t[j]-'0']--;
						}else{
							us[i][t[j]-'0']--;
							t[j] = (char)('0' + i);
						}
					}
				}
				if(gmin == null){
					gmin = new String(t);
				}else{
					String st = new String(t);
					if(st.compareTo(gmin) < 0){
						gmin = st;
					}
				}
			}
		}
		out.println(gmin);
	}

	void run() throws Exception
	{
		in = oj ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{
		new C2().run();
	}

	int ni() { return Integer.parseInt(in.next()); }
	long nl() { return Long.parseLong(in.next()); }
	double nd() { return Double.parseDouble(in.next()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.util.*;

public class C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.nextInt();
        int k = sc.nextInt();
        char[] numb = sc.next().toCharArray();
        ArrayList<Integer>[] indices = new ArrayList[10];
        for(int i=0;i<10;i++) indices[i]=new ArrayList<Integer>();
        for (int i = 0; i < numb.length; i++) {
            int idx = numb[i] - '0';
            indices[idx].add(i);
            if (indices[idx].size() == k) {
                System.out.println(0);
                System.out.println(new String(numb));
                return;
            }
        }
        int minVal = Integer.MAX_VALUE, minidx = 0;
        for (int i = 0; i < 10; i++) {
            int req = k - indices[i].size();
            int tmp = 0;
            int diff = 1;
            while (req > 0) {
                if (i + diff < 10) {
                    tmp += (diff * Math.min(req, indices[i + diff].size()));
                    req -= Math.min(req, indices[i + diff].size());
                }
                if (req == 0) {
                    break;
                }
                if (i - diff >= 0) {
                    tmp += (diff * Math.min(req, indices[i - diff].size()));
                    req -= Math.min(req, indices[i - diff].size());
                }
                diff++;
            }
            if (tmp < minVal) {
                minVal = tmp;
                minidx = i;
            }
        }
        int req = k - indices[minidx].size();
        int diff = 1;
        while (req > 0) {
            if (minidx + diff < 10) {
                int taken = Math.min(req, indices[minidx + diff].size());
                req -= taken;
                for (int i = 0; i < taken; i++)
                    numb[indices[minidx + diff].get(i)] = (char) (minidx + '0');
            }
            if (req == 0) {
                break;
            }
            if (minidx - diff >= 0) {
                int taken = Math.min(req, indices[minidx - diff].size());
                req -= taken;
                for (int i = 0; i < taken; i++)
                    numb[indices[minidx - diff].get(indices[minidx - diff]
                            .size()
                            - 1 - i)] = (char) (minidx + '0');
            }
            diff++;
        }
        System.out.println(minVal);
        System.out.println(new String(numb));
    }
}


import java.util.*;

public class C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.nextInt();
        int k = sc.nextInt();
        char[] numb = sc.next().toCharArray();
        ArrayList<Integer>[] indices = new ArrayList[10];
        for (int i = 0; i < 10; i++)
            indices[i] = new ArrayList<Integer>();
        for (int i = 0; i < numb.length; i++) {
            int idx = numb[i] - '0';
            indices[idx].add(i);
            if (indices[idx].size() == k) {
                System.out.println(0);
                System.out.println(new String(numb));
                return;
            }
        }
        int minVal = Integer.MAX_VALUE;
        LinkedList<Integer> minidx = new LinkedList<Integer>();
        for (int i = 0; i < 10; i++) {
            int req = k - indices[i].size();
            int tmp = 0;
            int diff = 1;
            while (req > 0) {
                if (i + diff < 10) {
                    tmp += (diff * Math.min(req, indices[i + diff].size()));
                    req -= Math.min(req, indices[i + diff].size());
                }
                if (req == 0) {
                    break;
                }
                if (i - diff >= 0) {
                    tmp += (diff * Math.min(req, indices[i - diff].size()));
                    req -= Math.min(req, indices[i - diff].size());
                }
                diff++;
            }
            if (tmp < minVal) {
                minVal = tmp;
                minidx = new LinkedList<Integer>();
                minidx.add(i);
            } else if (tmp == minVal) {
                minidx.add(i);
            }
        }
        PriorityQueue<String> q = new PriorityQueue<String>();
        while (!minidx.isEmpty()) {
            int minid = minidx.remove();
            char[] ar=new char[numb.length];
            for(int _=0;_<ar.length;_++) ar[_]=numb[_];
            int req = k - indices[minid].size();
            int diff = 1;
            while (req > 0) {
                if (minid + diff < 10) {
                    int taken = Math.min(req, indices[minid + diff].size());
                    req -= taken;
                    for (int i = 0; i < taken; i++)
                        ar[indices[minid + diff].get(i)] = (char) (minid + '0');
                }
                if (req == 0) {
                    break;
                }
                if (minid - diff >= 0) {
                    int taken = Math.min(req, indices[minid - diff].size());
                    req -= taken;
                    for (int i = 0; i < taken; i++)
                        ar[indices[minid - diff].get(indices[minid - diff]
                                .size()
                                - 1 - i)] = (char) (minid + '0');
                }
                diff++;
            }
            q.add(new String(ar));
        }
        System.out.println(minVal);
        System.out.println(q.remove());
    }
}


import java.io.*;
import java.util.StringTokenizer;

public class Q118C implements Runnable {
    private void solve() throws IOException {
        int n = nextInt();
        int k = nextInt();
        char[] num = nextToken().toCharArray();
        int[] count = new int[10];
        for (int i = 0; i < n; i++) {
            count[num[i] - '0']++;
        }

        //check already
        Object[] objects = getcost(0, count, k, num);
        for (int i = 1; i < 10; i++) {
            Object[] ob = getcost(i, count, k, num);
            if ((Integer) ob[0] < (Integer) objects[0] ||
                    ((Integer) ob[0]).intValue() == ((Integer) objects[0]).intValue()
                            && ob[1].toString().compareTo(objects[1].toString()) < 0) {
                objects = ob;
            }
        }
        writer.println(objects[0]);
        writer.print(objects[1]);
    }

    private void print(int minCost) {
        writer.print(minCost);
    }

    private Object[] getcost(int lucky, int[] count, int k, char[] num) {
        char[] newNum = new char[num.length];
        System.arraycopy(num, 0, newNum, 0, num.length);
        int left = k - count[lucky];
        int cost = 0;
        int closest = 0;
        while (left > 0) {
            if (closest >= 0) closest = -(closest + 1);
            else closest = (-closest);
            int nn = lucky + closest;
            if (nn >= 0 && nn < 10) {
                cost += Math.abs(nn - lucky) * Math.min(left, count[nn]);
                if (nn < lucky) {
                    changeFrom(newNum, nn, lucky, Math.min(left, count[nn]), true);
                } else {
                    changeFrom(newNum, nn, lucky, Math.min(left, count[nn]), false);
                }
                left -= count[nn];
            }
        }
        return new Object[]{cost, new String(newNum)};
    }

    private void changeFrom(char[] newNum, int nn, int lucky, int count, boolean right) {
        if (right)
            for (int i = newNum.length - 1; count > 0 && i >= 0; i--) {
                int c = newNum[i]-'0';
                if (c == nn) {
                    newNum[i] = (char) (lucky + '0');
                    count--;
                }
            }
        else
            for (int i = 0; i < newNum.length && count>0; i++) {
                int c = newNum[i]-'0';
                if (c == nn) {
                    newNum[i] = (char) (lucky + '0');
                    count--;
                }
            }
    }

    public static void main(String[] args) {
        new Q118C().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {

            boolean oj = System.getProperty("ONLINE_JUDGE") != null;

            reader = oj ? new BufferedReader(new InputStreamReader(System.in)) :
                    new BufferedReader(new FileReader(new File("input.txt")));

            tokenizer = null;
            writer = new PrintWriter(System.out);
            long start = System.currentTimeMillis();
            solve();
            reader.close();
            if (!oj) {
                writer.print("\nTime:" + (System.currentTimeMillis() - start));
            }
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}


import java.io.*;
import java.util.StringTokenizer;

public class Q118C implements Runnable {
    private void solve() throws IOException {
        int n = nextInt();
        int k = nextInt();
        char[] num = nextToken().toCharArray();
        int[] count = new int[10];
        for (int i = 0; i < n; i++) {
            count[num[i] - '0']++;
        }

        //check already
        Object[] objects = new Object[]{Integer.valueOf(Integer.MAX_VALUE)};
        for (int b = 0; b < 2; b++) {
            for (int i = 0; i < 10; i++) {
                Object[] ob = getcost(i, count, k, num, b);
                if ((Integer) ob[0] < (Integer) objects[0] ||
                        ((Integer) ob[0]).intValue() == ((Integer) objects[0]).intValue()
                                && ob[1].toString().compareTo(objects[1].toString()) < 0) {
                    objects = ob;
                }
            }
        }
        writer.println(objects[0]);
        writer.print(objects[1]);
    }

    private void print(int minCost) {
        writer.print(minCost);
    }

    private Object[] getcost(int lucky, int[] count, int k, char[] num, int b) {
        char[] newNum = new char[num.length];
        System.arraycopy(num, 0, newNum, 0, num.length);
        int left = k - count[lucky];
        int cost = 0;
        int closest = 0;
        while (left > 0) {
            if (b == 1) {
                if (closest >= 0) closest = -(closest + 1);
                else closest = (-closest);
            } else {
                if (closest <= 0) closest = -(closest - 1);
                else closest = (-closest);
            }
            int nn = lucky + closest;
            if (nn >= 0 && nn < 10) {
                cost += Math.abs(nn - lucky) * Math.min(left, count[nn]);
                if (nn < lucky) {
                    changeFrom(newNum, nn, lucky, Math.min(left, count[nn]), true);
                } else {
                    changeFrom(newNum, nn, lucky, Math.min(left, count[nn]), false);
                }
                left -= count[nn];
            }
        }
        return new Object[]{cost, new String(newNum)};
    }

    private void changeFrom(char[] newNum, int nn, int lucky, int count, boolean right) {
        if (right)
            for (int i = newNum.length - 1; count > 0 && i >= 0; i--) {
                int c = newNum[i] - '0';
                if (c == nn) {
                    newNum[i] = (char) (lucky + '0');
                    count--;
                }
            }
        else
            for (int i = 0; i < newNum.length && count > 0; i++) {
                int c = newNum[i] - '0';
                if (c == nn) {
                    newNum[i] = (char) (lucky + '0');
                    count--;
                }
            }
    }

    public static void main(String[] args) {
        new Q118C().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {

            boolean oj = System.getProperty("ONLINE_JUDGE") != null;

            reader = oj ? new BufferedReader(new InputStreamReader(System.in)) :
                    new BufferedReader(new FileReader(new File("input.txt")));

            tokenizer = null;
            writer = new PrintWriter(System.out);
            long start = System.currentTimeMillis();
            solve();
            reader.close();
            if (!oj) {
                writer.print("\nTime:" + (System.currentTimeMillis() - start));
            }
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}


import java.io.*;
import java.util.*;

public class CodeForce {

    private void solve() throws IOException {
        int []m = new int [10];
        int max_k = 0, max_i = 10;
        int n = nextInt(), k = nextInt();
        List<int []> li = new LinkedList<int[]>();
        StringBuilder buf = new StringBuilder(nextLine());
        for(int i = 0; i < buf.length(); i++) {
            int a = buf.charAt(i) - '0';
            m[a]++;
            if(m[a] >= max_k) {
                if(a < max_i) {
                    max_i = a;
                }
                max_k = m[a];
            }
            li.add(new int[]{a, i});
        }
        final int max = max_i;
        if(max_k < k) {
            Collections.sort(li, new Comparator<int []>() {
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    int d1 = Math.abs(arg0[0] - max), d2 = Math.abs(arg1[0] - max);
                    if(d1 < d2) return -1;
                    else if(d1 == d2) return arg0[1] - arg1[1];
                    return 1;
                }
            });
        }
        int c = 0;
        for(int i = 0; i < li.size() && max_k < k; i++) {
            int []a = li.get(i);
            if(a[0] == max_i) continue;
            buf.setCharAt(a[1], (char)(max_i + '0'));
            c += Math.abs(a[0] - max_i);
            max_k++;
        }
        System.out.println(c);
        System.out.println(buf.toString());
    }

    public static void main(String[] args) {
        new CodeForce().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(new FileOutputStream(new File("output.txt")));
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.io.*;
import java.util.*;

public class CodeForce {

    private void solve() throws IOException {
        int []m = new int [10];
        int n = nextInt(), k = nextInt();
        List<int []> li = new ArrayList<int[]>();
        StringBuilder buf = new StringBuilder(nextLine());
        for(int i = 0; i < buf.length(); i++) {
            int a = buf.charAt(i) - '0';
            m[a]++;
            li.add(new int[]{a, i});
        }
        int min_c = Integer.MAX_VALUE;
        String ret = buf.toString();
        for(int i = 0; i < 10; i++) {
            final int x = i;
            Collections.sort(li, new Comparator<int []>() {
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    int d1 = Math.abs(arg0[0] - x), d2 = Math.abs(arg1[0] - x);
                    if(d1 < d2) return -1;
                    else if(d1 == d2) {
                        if(x < arg0[0]) return -1;
                        else return 1;
                    }
                    return 1;
                }
            });
            int c = 0;
            int y = m[i];
            StringBuilder b = new StringBuilder(buf.toString());
            for(int j = 0; j < li.size() && y < k; j++) {
                int []a = li.get(j);
                if(a[0] == x) continue;
                b.setCharAt(a[1], (char)(x + '0'));
                c += Math.abs(a[0] - x);
                y++;
            }
            if(c < min_c) {
                min_c = c;
                ret = b.toString();
            } else if(c == min_c) {
                if(b.toString().compareTo(ret) < 0)
                    ret = b.toString();
            }
        }

        System.out.println(min_c);
        System.out.println(ret);
    }

    public static void main(String[] args) {
        new CodeForce().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(new FileOutputStream(new File("output.txt")));
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.io.*;
import java.util.*;

public class CodeForce {

    private void solve() throws IOException {
        int []m = new int [10];
        int n = nextInt(), k = nextInt();
        List<int []> li = new ArrayList<int[]>();
        StringBuilder buf = new StringBuilder(nextLine());
        for(int i = 0; i < buf.length(); i++) {
            int a = buf.charAt(i) - '0';
            m[a]++;
            li.add(new int[]{a, i});
        }
        int min_c = Integer.MAX_VALUE;
        String ret = buf.toString();
        for(int i = 0; i < 10; i++) {
            final int x = i;
            Collections.sort(li, new Comparator<int []>() {
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    int d1 = Math.abs(arg0[0] - x), d2 = Math.abs(arg1[0] - x);
                    if(d1 < d2) return -1;
                    else if(d1 == d2) {
                        if(arg0[1] < arg1[1]) {
                            if(x < arg0[0]) return -1;
                            return 1;
                        } else {
                            if(x < arg1[0]) return 1;
                            return -1;
                        }
                    }
                    return 1;
                }
            });
            int c = 0;
            int y = m[i];
            StringBuilder b = new StringBuilder(buf.toString());
            for(int j = 0; j < li.size() && y < k; j++) {
                int []a = li.get(j);
                if(a[0] == x) continue;
                b.setCharAt(a[1], (char)(x + '0'));
                c += Math.abs(a[0] - x);
                y++;
            }
            if(c < min_c) {
                min_c = c;
                ret = b.toString();
            } else if(c == min_c) {
                if(b.toString().compareTo(ret) < 0)
                    ret = b.toString();
            }
        }

        System.out.println(min_c);
        System.out.println(ret);
    }

    public static void main(String[] args) {
        new CodeForce().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(new FileOutputStream(new File("output.txt")));
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.io.*;
import java.util.*;

public class CodeForce {

    private void solve() throws IOException {
        int []m = new int [10];
        int n = nextInt(), k = nextInt();
        List<int []> li = new ArrayList<int[]>();
        StringBuilder buf = new StringBuilder(nextLine());
        for(int i = 0; i < buf.length(); i++) {
            int a = buf.charAt(i) - '0';
            m[a]++;
            li.add(new int[]{a, i});
        }
        int max_c = Integer.MAX_VALUE, max_i = 10;
        for(int i = 0; i < 10; i++) {
            final int x = i;
            Collections.sort(li, new Comparator<int []>() {
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    return Math.abs(arg0[0] - x) - Math.abs(arg1[0] - x);
                }
            });
            int c = 0;
            int y = m[i];
            for(int j = 0; j < li.size() && y < k; j++) {
                int []v = li.get(j);
                if(v[0] == i) continue;
                c += Math.abs(v[0] - i);
                y++;
            }
            if(c < max_c) {
                max_c = c;
                max_i = i;
            } else if(c == max_c && i < max_i) {
                max_c = c;
                max_i = i;
            }
        }
        int max_k = m[max_i];
        final int max = max_i;
        if(max_c > 0) {
            Collections.sort(li, new Comparator<int []>() {
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    int d1 = Math.abs(arg0[0] - max), d2 = Math.abs(arg1[0] - max);
                    if(d1 < d2) return -1;
                    else if(d1 == d2) return arg0[1] - arg1[1];
                    return 1;
                }
            });
        }
        int c = 0;

        for(int i = 0; i < li.size() && max_k < k; i++) {
            int []a = li.get(i);
            if(a[0] == max_i) continue;
            buf.setCharAt(a[1], (char)(max_i + '0'));
            c += Math.abs(a[0] - max_i);
            max_k++;
        }
        System.out.println(c);
        System.out.println(buf.toString());
    }

    public static void main(String[] args) {
        new CodeForce().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(new FileOutputStream(new File("output.txt")));
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.io.*;
import java.util.*;

public class CodeForce {

    private void solve() throws IOException {
        int []m = new int [10];
        int n = nextInt(), k = nextInt();
        List<int []> li = new ArrayList<int[]>();
        StringBuilder buf = new StringBuilder(nextLine());
        for(int i = 0; i < buf.length(); i++) {
            int a = buf.charAt(i) - '0';
            m[a]++;
            li.add(new int[]{a, i});
        }
        int max_c = Integer.MAX_VALUE, max_i = 10;
        for(int i = 0; i < 10; i++) {
            final int x = i;
            Collections.sort(li, new Comparator<int []>() {
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    return Math.abs(arg0[0] - x) - Math.abs(arg1[0] - x);
                }
            });
            int c = 0;
            int y = m[i];
            for(int j = 0; j < li.size() && y < k; j++) {
                int []v = li.get(j);
                if(v[0] == i) continue;
                c += Math.abs(v[0] - i);
                y++;
            }
            if(c < max_c) {
                max_c = c;
                max_i = i;
            } else if(c == max_c && i < max_i) {
                max_c = c;
                max_i = i;
            }
        }
        int max_k = m[max_i];
        final int max = max_i;
        if(max_c > 0) {
            Collections.sort(li, new Comparator<int []>() {
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    int d1 = Math.abs(arg0[0] - max), d2 = Math.abs(arg1[0] - max);
                    if(d1 < d2) return -1;
                    else if(d1 == d2) return arg1[1] - arg0[1];
                    return 1;
                }
            });
        }
        int c = 0;

        for(int i = 0; i < li.size() && max_k < k; i++) {
            int []a = li.get(i);
            if(a[0] == max_i) continue;
            buf.setCharAt(a[1], (char)(max_i + '0'));
            c += Math.abs(a[0] - max_i);
            max_k++;
        }
        System.out.println(c);
        System.out.println(buf.toString());
    }

    public static void main(String[] args) {
        new CodeForce().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(new FileOutputStream(new File("output.txt")));
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.io.*;
import java.util.*;

public class CodeForce {

    private void solve() throws IOException {
        int []m = new int [10];
        int n = nextInt(), k = nextInt();
        List<int []> li = new ArrayList<int[]>();
        StringBuilder buf = new StringBuilder(nextLine());
        for(int i = 0; i < buf.length(); i++) {
            int a = buf.charAt(i) - '0';
            m[a]++;
            li.add(new int[]{a, i});
        }
        int max_c = Integer.MAX_VALUE, max_i = 10;
        for(int i = 0; i < 10; i++) {
            final int x = i;
            Collections.sort(li, new Comparator<int []>() {
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    return Math.abs(arg0[0] - x) - Math.abs(arg1[0] - x);
                }
            });
            int c = 0;
            int y = m[i];
            for(int j = 0; j < li.size() && y < k; j++) {
                int []v = li.get(j);
                if(v[0] == i) continue;
                c += Math.abs(v[0] - i);
                y++;
            }
            if(c < max_c) {
                max_c = c;
                max_i = i;
            } else if(c == max_c && i < max_i) {
                max_c = c;
                max_i = i;
            }
        }
        int max_k = m[max_i];
        final int max = max_i;
        if(max_c > 0) {
            Collections.sort(li, new Comparator<int []>() {
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    int d1 = Math.abs(arg0[0] - max), d2 = Math.abs(arg1[0] - max);
                    if(d1 < d2) return -1;
                    else if(d1 == d2) {
                        if(max < arg0[0]) return -1;
                        else return 1;
                    }
                    return 1;
                }
            });
        }
        int c = 0;

        for(int i = 0; i < li.size() && max_k < k; i++) {
            int []a = li.get(i);
            if(a[0] == max_i) continue;
            buf.setCharAt(a[1], (char)(max_i + '0'));
            c += Math.abs(a[0] - max_i);
            max_k++;
        }
        System.out.println(c);
        System.out.println(buf.toString());
    }

    public static void main(String[] args) {
        new CodeForce().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(new FileOutputStream(new File("output.txt")));
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;

public class C {

	static boolean test = false;

	private void solve() throws Throwable {
		int n = iread(), k = iread();

		String s = wread();
		int[] cnt = new int[10];
		for (int i = 0; i < s.length(); i++) {
			cnt[s.charAt(i) - '0']++;
		}

		int best = Integer.MAX_VALUE;
		int[] values = new int[n];
		String res = "";
		for (int i = 0; i < s.length(); i++) {
			values[i] = s.charAt(i) - '0';
		}

		for (int target = 0; target <= 9; target++) {
			boolean[] changed = new boolean[n];
			int rem = k - cnt[target];
			int cost = 0;
			while (rem > 0) {
				for (int mod = 1; mod <= 9; mod++) {
					for (int factor = 1; factor > -2; factor -= 2) {
						int val = mod * factor + target;
						if (rem > 0 && val <= 9 && val >= 0) {
							int tmp = rem;
							rem -= cnt[val];
							cost += cnt[val] * mod;
							tmp -= Math.max(0, rem);
							if (rem < 0) {
								cost -= Math.abs(rem * mod);
								rem = 0;
							}
							if(mod > 0){
								for (int i = 0; i < values.length; i++) {
									if (tmp > 0 && values[i] == val) {
										changed[i] = true;
										tmp--;
									}
								}
							} else {
								for (int i = values.length - 1 ; i >= 0; i--) {
									if (tmp > 0 && values[i] == val) {
										changed[i] = true;
										tmp--;
									}
								}
							}
						}
					}
				}
			}
			if (cost < best) {
				best = cost;
				StringBuilder b = new StringBuilder();
				for (int i = 0; i < changed.length; i++) {
					if (changed[i]) {
						b.append(target);
					} else {
						b.append(values[i]);
					}
				}
				res = b.toString();
			}
		}
		out.write(best + "\n");
		out.write(res);
	}

	public int iread() throws Exception {
		return Integer.parseInt(wread());
	}

	public double dread() throws Exception {
		return Double.parseDouble(wread());
	}

	public long lread() throws Exception {
		return Long.parseLong(wread());
	}

	public String wread() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) throws Throwable {
		new C().solve();
		out.close();
	}

	public C() throws Throwable {
		if (test) {
			in = new BufferedReader(new FileReader(new File(testDataFile)));
		} else {
			new BufferedReader(inp);
		}
	}

	static InputStreamReader inp = new InputStreamReader(System.in);
	static BufferedReader in = new BufferedReader(inp);
	static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

	static String testDataFile = "testdata.txt";
	BufferedReader reader = null;
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;

public class C {

        static boolean test = false;

        private void solve() throws Throwable {
        	int n = iread(), k = iread();

        	String s = wread();
        	int[] cnt = new int[10];
        	for (int i = 0; i < s.length(); i++) {
				cnt[s.charAt(i) - '0'] ++;
			}

        	int best = Integer.MAX_VALUE;
        	int[] values = new int[n];
        	String res = "";
        	for (int i = 0; i < s.length(); i++) {
        		values[i] = s.charAt(i) - '0';
        	}

        	for (int target = 0; target <= 9; target++) {
        		boolean[] changed = new boolean[n];
        		int rem = k - cnt[target];
        		int cost = 0;
        		while (rem > 0) {
					for (int mod = 1; mod <= 9; mod++) {
						for (int factor = 1; factor > -2; factor -= 2) {
							int val = mod*factor+target;
							if(rem > 0 && val <= 9 && val >= 0){
								int tmp = rem;
								rem -= cnt[val];
								cost += cnt[val]*mod;
								tmp -= Math.max(0, rem);
								if(rem < 0){
									cost -= Math.abs(rem *mod);
									rem = 0;
								}
								for (int i = 0; i < values.length; i++) {
									if(tmp > 0 && values[i] == val){
										changed[i] = true;
										tmp --;
									}
								}
							}
						}
					}
        		}
        		if(cost < best){
        			best = cost;
        			StringBuilder b = new StringBuilder();
        			for (int i = 0; i < changed.length; i++) {
						if(changed[i]){
							b.append(target);
						} else {
							b.append(values[i]);
						}
					}
        			res = b.toString();
        		}
			}
        	out.write(best + "\n");
        	out.write(res);
        }

        public int iread() throws Exception {
                return Integer.parseInt(wread());
        }

        public double dread() throws Exception {
                return Double.parseDouble(wread());
        }

        public long lread() throws Exception {
                return Long.parseLong(wread());
        }

        public String wread() throws IOException {
                StringBuilder b = new StringBuilder();
                int c;
                c = in.read();
                while (c >= 0 && c <= ' ')
                        c = in.read();
                if (c < 0)
                        return "";
                while (c > ' ') {
                        b.append((char) c);
                        c = in.read();
                }
                return b.toString();
        }

        public static void main(String[] args) throws Throwable {
                new C().solve();
                out.close();
        }

        public C() throws Throwable {
                if (test) {
                        in = new BufferedReader(new FileReader(new File(testDataFile)));
                } else {
                        new BufferedReader(inp);
                }
        }

        static InputStreamReader inp = new InputStreamReader(System.in);
        static BufferedReader in = new BufferedReader(inp);
        static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

        static String testDataFile = "testdata.txt";
        BufferedReader reader = null;
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;

public class C {

        static boolean test = false;

        private void solve() throws Throwable {
        	int n = iread(), k = iread();

        	String s = wread();
        	int[] cnt = new int[10];
        	for (int i = 0; i < s.length(); i++) {
				cnt[s.charAt(i) - '0'] ++;
			}

        	int best = Integer.MAX_VALUE;
        	int[] values = new int[n];
        	String res = "";
        	for (int i = 0; i < s.length(); i++) {
        		values[i] = s.charAt(i) - '0';
        	}

        	for (int target = 0; target <= 9; target++) {
        		boolean[] changed = new boolean[n];
        		int rem = k - cnt[target];
        		int cost = 0;
        		while (rem > 0) {
					for (int mod = 1; mod <= 9; mod++) {
						for (int factor = 1; factor > -2; factor -= 2) {
							int val = mod*factor+target;
							if(rem > 0 && val <= 9 && val >= 0){
								int tmp = rem;
								rem -= cnt[val];
								cost += cnt[val]*mod;
								tmp -= rem;
								if(rem < 0){
									cost -= Math.abs(rem *mod);
									rem = 0;
								}
								for (int i = 0; i < values.length; i++) {
									if(tmp > 0 && values[i] == val){
										changed[i] = true;
									}
								}
							}
						}
					}
        		}
        		if(cost < best){
        			best = cost;
        			StringBuilder b = new StringBuilder();
        			for (int i = 0; i < changed.length; i++) {
						if(changed[i]){
							b.append(target);
						} else {
							b.append(values[i]);
						}
					}
        			res = b.toString();
        		}
			}
        	out.write(best + "\n");
        	out.write(res);
        }

        public int iread() throws Exception {
                return Integer.parseInt(wread());
        }

        public double dread() throws Exception {
                return Double.parseDouble(wread());
        }

        public long lread() throws Exception {
                return Long.parseLong(wread());
        }

        public String wread() throws IOException {
                StringBuilder b = new StringBuilder();
                int c;
                c = in.read();
                while (c >= 0 && c <= ' ')
                        c = in.read();
                if (c < 0)
                        return "";
                while (c > ' ') {
                        b.append((char) c);
                        c = in.read();
                }
                return b.toString();
        }

        public static void main(String[] args) throws Throwable {
                new C().solve();
                out.close();
        }

        public C() throws Throwable {
                if (test) {
                        in = new BufferedReader(new FileReader(new File(testDataFile)));
                } else {
                        new BufferedReader(inp);
                }
        }

        static InputStreamReader inp = new InputStreamReader(System.in);
        static BufferedReader in = new BufferedReader(inp);
        static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

        static String testDataFile = "testdata.txt";
        BufferedReader reader = null;
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;

public class C {

	static boolean test = false;

	private void solve() throws Throwable {
		int n = iread(), k = iread();

		String s = wread();
		int[] cnt = new int[10];
		for (int i = 0; i < s.length(); i++) {
			cnt[s.charAt(i) - '0']++;
		}

		int best = Integer.MAX_VALUE;
		int[] values = new int[n];
		String res = "";
		for (int i = 0; i < s.length(); i++) {
			values[i] = s.charAt(i) - '0';
		}

		for (int target = 0; target <= 9; target++) {
			boolean[] changed = new boolean[n];
			int rem = k - cnt[target];
			int cost = 0;
			while (rem > 0) {
				for (int mod = 1; mod <= 9; mod++) {
					for (int factor = 1; factor > -2; factor -= 2) {
						int val = mod * factor + target;
						if (rem > 0 && val <= 9 && val >= 0) {
							int tmp = rem;
							rem -= cnt[val];
							cost += cnt[val] * mod;
							tmp -= Math.max(0, rem);
							if (rem < 0) {
								cost -= Math.abs(rem * mod);
								rem = 0;
							}
							if(factor > 0){
								for (int i = 0; i < values.length; i++) {
									if (tmp > 0 && values[i] == val) {
										changed[i] = true;
										tmp--;
									}
								}
							} else {
								for (int i = values.length - 1 ; i >= 0; i--) {
									if (tmp > 0 && values[i] == val) {
										changed[i] = true;
										tmp--;
									}
								}
							}
						}
					}
				}
			}
			if (cost < best) {
				best = cost;
				StringBuilder b = new StringBuilder();
				for (int i = 0; i < changed.length; i++) {
					if (changed[i]) {
						b.append(target);
					} else {
						b.append(values[i]);
					}
				}
				res = b.toString();
			}
		}
		out.write(best + "\n");
		out.write(res);
	}

	public int iread() throws Exception {
		return Integer.parseInt(wread());
	}

	public double dread() throws Exception {
		return Double.parseDouble(wread());
	}

	public long lread() throws Exception {
		return Long.parseLong(wread());
	}

	public String wread() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) throws Throwable {
		new C().solve();
		out.close();
	}

	public C() throws Throwable {
		if (test) {
			in = new BufferedReader(new FileReader(new File(testDataFile)));
		} else {
			new BufferedReader(inp);
		}
	}

	static InputStreamReader inp = new InputStreamReader(System.in);
	static BufferedReader in = new BufferedReader(inp);
	static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

	static String testDataFile = "testdata.txt";
	BufferedReader reader = null;
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;

public class C {

        static boolean test = false;

        private void solve() throws Throwable {
        	int n = iread(), k = iread();

        	String s = wread();
        	int[] cnt = new int[10];
        	for (int i = 0; i < s.length(); i++) {
				cnt[s.charAt(i) - '0'] ++;
			}

        	int best = Integer.MAX_VALUE;
        	int[] values = new int[n];
        	String res = "";
        	for (int i = 0; i < s.length(); i++) {
        		values[i] = s.charAt(i) - '0';
        	}

        	for (int target = 0; target <= 9; target++) {
        		boolean[] changed = new boolean[n];
        		int rem = k - cnt[target];
        		int cost = 0;
        		while (rem > 0) {
					for (int mod = 1; mod <= 9; mod++) {
						for (int factor = 1; factor > -2; factor -= 2) {
							int val = mod*factor+target;
							if(rem > 0 && val <= 9 && val >= 0){
								int tmp = rem;
								rem -= cnt[val];
								cost += cnt[val]*mod;
								tmp -= rem;
								if(rem < 0){
									cost -= Math.abs(rem *mod);
									rem = 0;
								}
								for (int i = 0; i < values.length; i++) {
									if(tmp > 0 && values[i] == val){
										changed[i] = true;
									}
								}
							}
						}
					}
        		}
        		if(cost < best){
        			best = cost;
        			StringBuilder b = new StringBuilder();
        			for (int i = 0; i < changed.length; i++) {
						if(changed[i]){
							b.append(target);
						} else {
							b.append(values[i]);
						}
					}
        			res = b.toString();
        		}
			}
        	out.write(res);
        }

        public int iread() throws Exception {
                return Integer.parseInt(wread());
        }

        public double dread() throws Exception {
                return Double.parseDouble(wread());
        }

        public long lread() throws Exception {
                return Long.parseLong(wread());
        }

        public String wread() throws IOException {
                StringBuilder b = new StringBuilder();
                int c;
                c = in.read();
                while (c >= 0 && c <= ' ')
                        c = in.read();
                if (c < 0)
                        return "";
                while (c > ' ') {
                        b.append((char) c);
                        c = in.read();
                }
                return b.toString();
        }

        public static void main(String[] args) throws Throwable {
                new C().solve();
                out.close();
        }

        public C() throws Throwable {
                if (test) {
                        in = new BufferedReader(new FileReader(new File(testDataFile)));
                } else {
                        new BufferedReader(inp);
                }
        }

        static InputStreamReader inp = new InputStreamReader(System.in);
        static BufferedReader in = new BufferedReader(inp);
        static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

        static String testDataFile = "testdata.txt";
        BufferedReader reader = null;
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;

public class C {

	static boolean test = false;

	private void solve() throws Throwable {
		int n = iread(), k = iread();

		String s = wread();
		int[] cnt = new int[10];
		for (int i = 0; i < s.length(); i++) {
			cnt[s.charAt(i) - '0']++;
		}

		int best = Integer.MAX_VALUE;
		int[] values = new int[n];
		String res = "";
		for (int i = 0; i < s.length(); i++) {
			values[i] = s.charAt(i) - '0';
		}

		for (int target = 0; target <= 9; target++) {
			boolean[] changed = new boolean[n];
			int rem = k - cnt[target];
			int cost = 0;
			while (rem > 0) {
				for (int mod = 1; mod <= 9; mod++) {
					for (int factor = 1; factor > -2; factor -= 2) {
						int val = mod * factor + target;
						if (rem > 0 && val <= 9 && val >= 0) {
							int tmp = rem;
							rem -= cnt[val];
							cost += cnt[val] * mod;
							tmp -= Math.max(0, rem);
							if (rem < 0) {
								cost -= Math.abs(rem * mod);
								rem = 0;
							}
							if(factor > 0){
								for (int i = 0; i < values.length; i++) {
									if (tmp > 0 && values[i] == val) {
										changed[i] = true;
										tmp--;
									}
								}
							} else {
								for (int i = values.length - 1 ; i >= 0; i--) {
									if (tmp > 0 && values[i] == val) {
										changed[i] = true;
										tmp--;
									}
								}
							}
						}
					}
				}
			}
			StringBuilder b = new StringBuilder();
			for (int i = 0; i < changed.length; i++) {
				if (changed[i]) {
					b.append(target);
				} else {
					b.append(values[i]);
				}
			}
//			res = b.toString();
			if (cost < best || (cost <= best && (b.toString().compareTo(res) <= 0 || res.compareTo("") == 0))){
				best = cost;
				res = b.toString();
			}
		}
		out.write(best + "\n");
		out.write(res);
	}

	public int iread() throws Exception {
		return Integer.parseInt(wread());
	}

	public double dread() throws Exception {
		return Double.parseDouble(wread());
	}

	public long lread() throws Exception {
		return Long.parseLong(wread());
	}

	public String wread() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) throws Throwable {
		new C().solve();
		out.close();
	}

	public C() throws Throwable {
		if (test) {
			in = new BufferedReader(new FileReader(new File(testDataFile)));
		} else {
			new BufferedReader(inp);
		}
	}

	static InputStreamReader inp = new InputStreamReader(System.in);
	static BufferedReader in = new BufferedReader(inp);
	static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

	static String testDataFile = "testdata.txt";
	BufferedReader reader = null;
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {

	static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	static PrintWriter out = new PrintWriter(System.out);

	static String nextToken() throws IOException{
		while (st==null || !st.hasMoreTokens()){
			String s = bf.readLine();
			if (s == null)
				return null;
			st = new StringTokenizer(s);
		}

		return st.nextToken();
	}

	static int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException{
		return Long.parseLong(nextToken());
	}

	static String nextStr() throws IOException{
		return nextToken();
	}

	static double nextDouble() throws IOException{
		return Double.parseDouble(nextToken());
	}

	static int f(byte s[], int a[], int k, byte d){
		int res = 0;
		int p = a[d];

		int l = d-1,
			r = d+1;
		while (p < k){
			if (r <= 9){
				int t = Math.min(k-p, a[r]);
				p += t;
				res += t*(r-d);

				int m = 0;
				for (int i=0; i<s.length && m<t; i++)
					if (s[i] == r){
						s[i] = d;
						m++;
					}

				r++;
			}

			if (l >= 0){
				int t = Math.min(k-p, a[l]);
				p += t;
				res += t*(d-l);

				int m = 0;
				for (int i=s.length-1; i>=0 && m<t; i--)
					if (s[i] == l){
						s[i] = d;
						m++;
					}

				l--;
			}

		}

		return res;
	}

	public static void main(String[] args) throws IOException{
		int n = nextInt(),
			k = nextInt();

		byte s[] = nextStr().getBytes();
		int a[] = new int[10];
		for (int i=0; i<n; i++){
			s[i] -= '0';
			a[s[i]]++;
		}

		byte res[] = null;
		int min = 1000000000;

		for (int i=0; i<10; i++){
			byte t[] = new byte[n];
			for (int j=0; j<n; j++)
				t[j] = s[j];
			int p = f(t, a, k, (byte)i);
			if (p < min){
				min = p;
				res = t;
			}

		}

		out.println(min);
		for (int i=0; i<n; i++)
			out.print((char)(res[i]+'0'));
		out.flush();
	}

}


//package round89;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {

	static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	static PrintWriter out = new PrintWriter(System.out);

	static String nextToken() throws IOException{
		while (st==null || !st.hasMoreTokens()){
			String s = bf.readLine();
			if (s == null)
				return null;
			st = new StringTokenizer(s);
		}

		return st.nextToken();
	}

	static int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException{
		return Long.parseLong(nextToken());
	}

	static String nextStr() throws IOException{
		return nextToken();
	}

	static double nextDouble() throws IOException{
		return Double.parseDouble(nextToken());
	}

	static int f(byte s[], int a[], int k, byte d){
		int res = 0;
		int p = a[d];

		int l = d-1,
			r = d+1;
		while (p < k){
			if (r <= 9){
				int t = Math.min(k-p, a[r]);
				p += t;
				res += t*(r-d);

				int m = 0;
				for (int i=0; i<s.length && m<t; i++)
					if (s[i] == r){
						s[i] = d;
						m++;
					}

				r++;
			}

			if (l >= 0){
				int t = Math.min(k-p, a[l]);
				p += t;
				res += t*(d-l);

				int m = 0;
				for (int i=s.length-1; i>=0 && m<t; i--)
					if (s[i] == l){
						s[i] = d;
						m++;
					}
			}

			l--;
		}

		return res;
	}

	public static void main(String[] args) throws IOException{
		int n = nextInt(),
			k = nextInt();

		byte s[] = nextStr().getBytes();
		int a[] = new int[10];
		for (int i=0; i<n; i++){
			s[i] -= '0';
			a[s[i]]++;
		}

		byte res[] = null;
		int min = 1000000000;

		for (int i=0; i<10; i++){
			byte t[] = new byte[n];
			for (int j=0; j<n; j++)
				t[j] = s[j];
			int p = f(t, a, k, (byte)i);
			if (p < min){
				min = p;
				res = t;
			}

		}

		out.println(min);
		for (int i=0; i<n; i++)
			out.print((char)(res[i]+'0'));
		out.flush();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static PrintWriter out = new PrintWriter(System.out);

    static String nextToken() throws IOException{
        while (st==null || !st.hasMoreTokens()){
            String s = bf.readLine();
            if (s == null)
                return null;
            st = new StringTokenizer(s);
        }

        return st.nextToken();
    }

    static int nextInt() throws IOException{
        return Integer.parseInt(nextToken());
    }

    static long nextLong() throws IOException{
        return Long.parseLong(nextToken());
    }

    static String nextStr() throws IOException{
        return nextToken();
    }

    static double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }

    static int f(byte s[], int a[], int k, byte d){
        int res = 0;
        int p = a[d];

        int l = d-1,
            r = d+1;
        while (p < k){
            if (r <= 9){
                int t = Math.min(k-p, a[r]);
                p += t;
                res += t*(r-d);

                int m = 0;
                for (int i=0; i<s.length && m<t; i++)
                    if (s[i] == r){
                        s[i] = d;
                        m++;
                    }

                r++;
            }

            if (l >= 0){
                int t = Math.min(k-p, a[l]);
                p += t;
                res += t*(d-l);

                int m = 0;
                for (int i=s.length-1; i>=0 && m<t; i--)
                    if (s[i] == l){
                        s[i] = d;
                        m++;
                    }

                l--;
            }

        }

        return res;
    }

    public static void main(String[] args) throws IOException{
        int n = nextInt(),
            k = nextInt();

        byte s[] = nextStr().getBytes();
        int a[] = new int[10];
        for (int i=0; i<n; i++){
            s[i] -= '0';
            a[s[i]]++;
        }

        byte res[] = null;
        int min = 1000000000;

        for (int i=0; i<10; i++){
            byte t[] = new byte[n];
            for (int j=0; j<n; j++)
                t[j] = s[j];
            int p = f(t, a, k, (byte)i);
            if (p<min || p==min && (new String(res)).compareTo(new String(t))>0){
                min = p;
                res = t;
            }

        }

        out.println(min);
        for (int i=0; i<n; i++)
            out.print((char)(res[i]+'0'));
        out.flush();
    }

}


package round89;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {

	static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	static PrintWriter out = new PrintWriter(System.out);

	static String nextToken() throws IOException{
		while (st==null || !st.hasMoreTokens()){
			String s = bf.readLine();
			if (s == null)
				return null;
			st = new StringTokenizer(s);
		}

		return st.nextToken();
	}

	static int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException{
		return Long.parseLong(nextToken());
	}

	static String nextStr() throws IOException{
		return nextToken();
	}

	static double nextDouble() throws IOException{
		return Double.parseDouble(nextToken());
	}

	static int f(byte s[], int a[], int k, byte d){
		int res = 0;
		int p = a[d];

		int l = d-1,
			r = d+1;
		while (p < k){
			if (r <= 9){
				int t = Math.min(k-p, a[r]);
				p += t;
				res += t*(r-d);

				int m = 0;
				for (int i=0; i<s.length && m<t; i++)
					if (s[i] == r){
						s[i] = d;
						m++;
					}

				r++;
			}

			if (l >= 0){
				int t = Math.min(k-p, a[l]);
				p += t;
				res += t*(d-l);

				int m = 0;
				for (int i=s.length-1; i>=0 && m<t; i--)
					if (s[i] == l){
						s[i] = d;
						m++;
					}

				l--;
			}

		}

		return res;
	}

	public static void main(String[] args) throws IOException{
		int n = nextInt(),
			k = nextInt();

		byte s[] = nextStr().getBytes();
		int a[] = new int[10];
		for (int i=0; i<n; i++){
			s[i] -= '0';
			a[s[i]]++;
		}

		byte res[] = null;
		int min = 1000000000;

		for (int i=0; i<10; i++){
			byte t[] = new byte[n];
			for (int j=0; j<n; j++)
				t[j] = s[j];
			int p = f(t, a, k, (byte)i);
			if (p < min){
				min = p;
				res = t;
			}

		}

		out.println(min);
		for (int i=0; i<n; i++)
			out.print((char)(res[i]+'0'));
		out.flush();
	}

}