import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Solution118C {

        final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");

        void init() throws FileNotFoundException{
                if (ONLINE_JUDGE){
                        in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
                }else{
                        in = new BufferedReader(new FileReader("input.txt"));
                        out = new PrintWriter("output.txt");
                }
        }

        String readString() throws IOException{
                while(!tok.hasMoreTokens()){
                        tok = new StringTokenizer(in.readLine());
                }
                return tok.nextToken();
        }

        int readInt() throws IOException{
                return Integer.parseInt(readString());
        }

        long readLong() throws IOException{
                return Long.parseLong(readString());
        }

        double readDouble() throws IOException{
                return Double.parseDouble(readString());
        }

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

        public void run(){
                try{
                        long t1 = System.currentTimeMillis();
                        init();
                        solve();
                        out.close();
                        long t2 = System.currentTimeMillis();
                        System.err.println("Time = "+(t2-t1));
                }catch (Exception e){
                        e.printStackTrace(System.err);
                        System.exit(-1);
                }
        }

        void solve() throws IOException{
        	int n = readInt();
        	int k = readInt();
        	String inp = readString();
        	char[] t = inp.toCharArray();
        	int[] nums = new int[10];
        	for(int i = 0; i < t.length; i++){
        		nums[t[i] - '0']++;
        	}
        	int minCost = Integer.MAX_VALUE;
        	char[] maxStr = inp.toCharArray();

        	for(int i = 0; i < 10; i++){
        		int cost = 0;
        		int num = nums[i];
        		char[] cur = inp.toCharArray();
        		for(int j = 1; j < 10; j++){
        			if(num > k) break;

        			if(i + j < 10){
        				if(nums[i+j] > 0){
        					if(k - num - nums[i+j] > 0){
        						num += nums[i+j];
        						cost += j * nums[i+j];
        						for(int l = 0; l < n; l++){
        							if(t[l] == i + j + '0'){
        								cur[l] = (char) ('0' + i);
        							}
        						}
        					}
        					else{
        						int curStep = k - num;
        						num += curStep;
        						cost += curStep * j;
        						for(int l = 0; l < n && curStep > 0; l++){
        							if(t[l] == i + j + '0'){
        								cur[l] = (char) ('0' + i);
        								curStep--;
        							}
        						}
        						break;
        					}
        				}
        			}
        			if(i - j >= 0){
        				if(nums[i-j] > 0){
        					if(k - num - nums[i-j] > 0){
        						num += nums[i-j];
        						cost += j * nums[i-j];
        						for(int l = 0; l < n; l++){
        							if(t[l] == i - j + '0'){
        								cur[l] = (char) ('0' + i);
        							}
        						}
        					}
        					else{
        						int curStep = k - num;
        						num += curStep;
        						cost += curStep * j;
        						for(int l = n-1; l >= 0 && curStep > 0; l--){
        							if(t[l] == i - j + '0'){
        								cur[l] = (char) ('0' + i);
        								curStep--;
        							}
        						}
        						break;
        					}
        				}
        			}
        		}
        		if(cost < minCost){
        			minCost = cost;
        			for(int j = 0; j < n; j++){
        				maxStr[j] = cur[j];
        			}
        		}
        		else if(cost == minCost){
        			if((new String(cur)).compareTo(new String(maxStr)) < 0){
        				maxStr = (new String(cur)).toCharArray();
        			}
        		}
        	}
        	out.println(minCost);
        	out.println(maxStr);
        }

        static class Utils {

                private Utils() {}

                public static void mergeSort(int[] a) {
                        mergeSort(a, 0, a.length - 1);
                }

                private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
                        final int MAGIC_VALUE = 50;
                        if (leftIndex < rightIndex) {
                                if (rightIndex - leftIndex <= MAGIC_VALUE) {
                                        insertionSort(a, leftIndex, rightIndex);
                                } else {
                                        int middleIndex = (leftIndex + rightIndex) / 2;
                                        mergeSort(a, leftIndex, middleIndex);
                                        mergeSort(a, middleIndex + 1, rightIndex);
                                        merge(a, leftIndex, middleIndex, rightIndex);
                                }
                        }
                }

                private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
                        int length1 = middleIndex - leftIndex + 1;
                        int length2 = rightIndex - middleIndex;
                        int[] leftArray = new int[length1];
                        int[] rightArray = new int[length2];
                        System.arraycopy(a, leftIndex, leftArray, 0, length1);
                        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
                        for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
                                if (i == length1) {
                                        a[k] = rightArray[j++];
                                } else if (j == length2) {
                                        a[k] = leftArray[i++];
                                } else {
                                        a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
                                }
                        }
                }

                private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
                        for (int i = leftIndex + 1; i <= rightIndex; i++) {
                                int current = a[i];
                                int j = i - 1;
                                while (j >= leftIndex && a[j] > current) {
                                        a[j + 1] = a[j];
                                        j--;
                                }
                                a[j + 1] = current;
                        }
                }
        }

        boolean isPrime(int a){
        	for(int i = 2; i <= sqrt(a); i++)
        		if(a % i == 0) return false;
        	return true;
        }

        static double distance(long x1, long y1, long x2, long y2){
        	return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        }

        static long gcd(long a, long b){
        	if(min(a,b) == 0) return max(a,b);
        	return gcd(max(a, b) % min(a,b), min(a,b));
        }

        static long lcm(long a, long b){
        	return a * b /gcd(a, b);
        }
}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Solution118C {

        final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");

        void init() throws FileNotFoundException{
                if (ONLINE_JUDGE){
                        in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
                }else{
                        in = new BufferedReader(new FileReader("input.txt"));
                        out = new PrintWriter("output.txt");
                }
        }

        String readString() throws IOException{
                while(!tok.hasMoreTokens()){
                        tok = new StringTokenizer(in.readLine());
                }
                return tok.nextToken();
        }

        int readInt() throws IOException{
                return Integer.parseInt(readString());
        }

        long readLong() throws IOException{
                return Long.parseLong(readString());
        }

        double readDouble() throws IOException{
                return Double.parseDouble(readString());
        }

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

        public void run(){
                try{
                        long t1 = System.currentTimeMillis();
                        init();
                        solve();
                        out.close();
                        long t2 = System.currentTimeMillis();
                        System.err.println("Time = "+(t2-t1));
                }catch (Exception e){
                        e.printStackTrace(System.err);
                        System.exit(-1);
                }
        }

        void solve() throws IOException{
        	int n = readInt();
        	int k = readInt();
        	String inp = readString();
        	char[] t = inp.toCharArray();
        	int[] nums = new int[10];
        	for(int i = 0; i < t.length; i++){
        		nums[t[i] - '0']++;
        	}
        	int minCost = Integer.MAX_VALUE;
        	char[] maxStr = inp.toCharArray();

        	for(int i = 0; i < 10; i++){
        		int cost = 0;
        		int num = nums[i];
        		char[] cur = inp.toCharArray();
        		for(int j = 1; j < 10; j++){
        			if(i - j >= 0){
        				if(nums[i-j] > 0){
        					if(k - num - nums[i-j] > 0){
        						num += nums[i-j];
        						cost += j * nums[i-j];
        						for(int l = 0; l < n; l++){
        							if(t[l] == i - j + '0'){
        								cur[l] = (char) ('0' + i);
        							}
        						}
        					}
        					else{
        						int curStep = k - num;
        						num += curStep;
        						cost += curStep * j;
        						for(int l = n-1; l >= 0 && curStep > 0; l--){
        							if(t[l] == i - j + '0'){
        								cur[l] = (char) ('0' + i);
        								curStep--;
        							}
        						}
        						break;
        					}
        				}
        			}
        			if(i + j < 10){
        				if(nums[i+j] > 0){
        					if(k - num - nums[i+j] > 0){
        						num += nums[i+j];
        						cost += j * nums[i+j];
        						for(int l = 0; l < n; l++){
        							if(t[l] == i + j + '0'){
        								cur[l] = (char) ('0' + i);
        							}
        						}
        					}
        					else{
        						int curStep = k - num;
        						num += curStep;
        						cost += curStep * j;
        						for(int l = 0; l < n && curStep > 0; l++){
        							if(t[l] == i + j + '0'){
        								cur[l] = (char) ('0' + i);
        								curStep--;
        							}
        						}
        						break;
        					}
        				}
        			}
        		}
        		if(cost < minCost){
        			minCost = cost;
        			for(int j = 0; j < n; j++){
        				maxStr[j] = cur[j];
        			}
        		}
        		else if(cost == minCost){
        			if((new String(cur)).compareTo(new String(maxStr)) < 0){
        				maxStr = (new String(cur)).toCharArray();
        			}
        		}
        	}
        	out.println(minCost);
        	out.println(maxStr);
        }

        static class Utils {

                private Utils() {}

                public static void mergeSort(int[] a) {
                        mergeSort(a, 0, a.length - 1);
                }

                private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
                        final int MAGIC_VALUE = 50;
                        if (leftIndex < rightIndex) {
                                if (rightIndex - leftIndex <= MAGIC_VALUE) {
                                        insertionSort(a, leftIndex, rightIndex);
                                } else {
                                        int middleIndex = (leftIndex + rightIndex) / 2;
                                        mergeSort(a, leftIndex, middleIndex);
                                        mergeSort(a, middleIndex + 1, rightIndex);
                                        merge(a, leftIndex, middleIndex, rightIndex);
                                }
                        }
                }

                private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
                        int length1 = middleIndex - leftIndex + 1;
                        int length2 = rightIndex - middleIndex;
                        int[] leftArray = new int[length1];
                        int[] rightArray = new int[length2];
                        System.arraycopy(a, leftIndex, leftArray, 0, length1);
                        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
                        for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
                                if (i == length1) {
                                        a[k] = rightArray[j++];
                                } else if (j == length2) {
                                        a[k] = leftArray[i++];
                                } else {
                                        a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
                                }
                        }
                }

                private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
                        for (int i = leftIndex + 1; i <= rightIndex; i++) {
                                int current = a[i];
                                int j = i - 1;
                                while (j >= leftIndex && a[j] > current) {
                                        a[j + 1] = a[j];
                                        j--;
                                }
                                a[j + 1] = current;
                        }
                }
        }

        boolean isPrime(int a){
        	for(int i = 2; i <= sqrt(a); i++)
        		if(a % i == 0) return false;
        	return true;
        }

        static double distance(long x1, long y1, long x2, long y2){
        	return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        }

        static long gcd(long a, long b){
        	if(min(a,b) == 0) return max(a,b);
        	return gcd(max(a, b) % min(a,b), min(a,b));
        }

        static long lcm(long a, long b){
        	return a * b /gcd(a, b);
        }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class contestA {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer s = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(s.nextToken());
        int k = Integer.parseInt(s.nextToken());
        String X = in.readLine();
        char[] x = X.toCharArray();
        node[][] ar = new node[10][x.length];
        int best = Integer.MAX_VALUE;
        int K = Math.min(k, x.length);
        int[] dp = new int[10];
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < x.length; j++) {
                ar[i][j] = new node(Math.abs(x[j] - ('0' + i)), j);
            }
            Arrays.sort(ar[i]);
            int temp = 0;
            for (int j = 0; j < K; j++) {
                temp += ar[i][j].dif;
            }
            if (temp < best) {
                best = temp;
            }
            dp[i] = temp;
        }
        TreeSet<String> res = new TreeSet();
        for (int i = 0; i < ar.length; i++) {
            if (dp[i] == best) {
                StringBuffer st = new StringBuffer(X);
                for (int j = 0; j < K; j++) {
                    st.setCharAt(ar[i][j].ind, (char) (i + '0'));
                }
                res.add(new String(st));
            }
        }
        System.out.println(best);
        System.out.println(res.pollFirst());
    }
}

class node implements Comparable<node> {

    int dif, ind;

    public node(int dif, int ind) {
        this.dif = dif;
        this.ind = ind;
    }

    @Override
    public int compareTo(node o) {
        if (dif < o.dif || (dif == o.dif && ind < o.ind)) {
            return -1;
        }
        return 1;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class contestA {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer s = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(s.nextToken());
        int k = Integer.parseInt(s.nextToken());
        String X = in.readLine();
        char[] x = X.toCharArray();
        node[][] ar = new node[10][x.length];
        int best = Integer.MAX_VALUE;
        int K = Math.min(k, x.length);
        int[] dp = new int[10];
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < x.length; j++) {
                ar[i][j] = new node(Math.abs(x[j] - ('0' + i)), j,i>x[j]-'0');
            }
            Arrays.sort(ar[i]);
            int temp = 0;
            for (int j = 0; j < K; j++) {
                temp += ar[i][j].dif;
            }
            if (temp < best) {
                best = temp;
            }
            dp[i] = temp;
        }
        TreeSet<String> res = new TreeSet();
        for (int i = 0; i < ar.length; i++) {
            if (dp[i] == best) {
                StringBuffer st = new StringBuffer(X);
                for (int j = 0; j < K; j++) {
                    st.setCharAt(ar[i][j].ind, (char) (i + '0'));
                }
                res.add(new String(st));
            }
        }
        System.out.println(best);
        System.out.println(res.pollFirst());
    }
}

class node implements Comparable<node> {

    int dif, ind;
    boolean g;

    public node(int dif, int ind,boolean g) {
        this.dif = dif;
        this.ind = ind;
        this.g=g;
    }

    @Override
    public int compareTo(node o) {
        if (dif < o.dif ) {
            return -1;
        }
        else if(dif == o.dif && (ind < o.ind&&!g)||(ind>o.ind&&g))return -1;
        return 1;
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskC {

    class State implements Comparable<State>{
        int ix;
        int from;
        int to;
        int dif;

        State(int ix, int from, int to, int dif) {
            this.ix = ix;
            this.from = from;
            this.to = to;
            this.dif = dif;
        }

        public int compareTo(State o) {
            if(dif != o.dif) return dif - o.dif;
            if(from < to) {
                return o.ix - ix;
            }
            else {
                return ix - o.ix;
            }
        }
    }

    void run() {
        int n = nextInt(), k = nextInt();
        String s = next();
        int[] sa = new int[n];
        for(int i = 0; i < n; i++) sa[i] = s.charAt(i) - '0';

        int min = Integer.MAX_VALUE;
        String ans = "";

        for(int i = 0; i < 10; i++) {
            State[] states = new State[n];
            for(int j = 0; j < n; j++) {
                states[j] = new State(j, sa[j], i, Math.abs(sa[j] - i));
            }
            Arrays.sort(states);

            int cost = 0;
            for(int j = 0; j < k; j++) cost += states[j].dif;
            if(cost < min) {
                min = cost;
                int[] sb = sa.clone();
                for(int j = 0; j < k; j++) sb[states[j].ix] = i;
                String res = "";
                for(int j = 0; j < n; j++) res += (char) (sb[j] + '0');
                ans = res;
            } else if(cost == min) {
                int[] sb = sa.clone();
                for(int j = 0; j < k; j++) sb[states[j].ix] = i;
                String res = "";
                for(int j = 0; j < n; j++) res += (char) (sb[j] + '0');
                if(ans.compareTo(res) > 0) ans = res;
            }
        }

        System.out.println(min);
        System.out.println(ans);
    }

    int nextInt() {
        try {
            int c = System.in.read();
            if (c == -1) return c;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return c;
            }
            if (c == '-') return -nextInt();
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    long nextLong() {
        try {
            int c = System.in.read();
            if (c == -1) return -1;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return -1;
            }
            if (c == '-') return -nextLong();
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String next() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (Character.isWhitespace(c))
                c = System.in.read();
            do {
                res.append((char) c);
            } while (!Character.isWhitespace(c = System.in.read()));
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

    String nextLine() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (c == '\r' || c == '\n')
                c = System.in.read();
            do {
                res.append((char) c);
                c = System.in.read();
            } while (c != '\r' && c != '\n');
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

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


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

//created at 7:44 PM 10/13/11 by Abrackadabra

public class C {
    int IOMode = 0; //0 - consoleIO, 1 - <taskName>.in/out, 2 - input.txt/output.txt, 3 - test case generator
    String taskName = "";

    void solve() throws IOException {
        int n = Integer.parseInt(nextString()), m = Integer.parseInt(nextString());
        String s = nextString();
        int min = 1000000;
        int[] best = new int[n];
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = s.charAt(i) - '0';
        for (int d = 0; d < 10; d++) {
            int[] b = new int[n];
            int c = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] != d)
                    c++;
                b[i] = a[i];
            }
            c = Math.max(m - (n - c), 0);
            int C = 0;
            for (int q = 1; q < 10; q++) {
                for (int i = 0; i < n; i++) {
                    if (c == 0) break;
                    if (b[i] == d + q) {
                        b[i] = d;
                        c--;
                        C += q;
                    }
                }
                for (int i = 0; i < n; i++) {
                    if (c == 0) break;
                    if (b[i] == d - q) {
                        b[i] = d;
                        c--;
                        C += q;
                    }
                }
            }
            if (C < min) {
                min = C;
                best = b;
            }
            if (C == min) {
                boolean ch = false;
                for (int i = 0; i < n; i++) {
                    if (b[i] < best[i]) {
                        ch = true;
                        break;
                    }
                    if (b[i] > best[i]) break;
                }
                if (ch) best = b;
            }
        }
        out.println(min);
        for (int i = 0; i < n; i++)
            out.print(best[i]);
    }

    public static void main(String[] args) throws IOException {
        if (args.length > 0 && args[0].equals("Abra")) debugMode = true;
        new C().run();
    }

    long startTime = System.nanoTime(), tempTime = startTime, finishTime = startTime;
    long startMem = Runtime.getRuntime().totalMemory(), finishMem = startMem;

    void run() throws IOException {
        init();
        if (debugMode) {
            con.println("Start");
            con.println("Console output:");
        }
        solve();
        finishTime = System.nanoTime();
        finishMem = Runtime.getRuntime().totalMemory();
        out.flush();
        if (debugMode) {
            int maxSymbols = 1000, c = 0;
            BufferedReader tbr = new BufferedReader(new FileReader("input.txt"));
            char[] a = new char[maxSymbols];
            tbr.read(a);
            if (a[0] != 0) {
                con.println();
                con.println("File input:");
                con.print(a);
            }
            boolean left = true;
            for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;
            if (left) con.println("...");
            else con.println();
            tbr = new BufferedReader(new FileReader("output.txt"));
            a = new char[maxSymbols];
            tbr.read(a);
            if (a[0] != 0) {
                con.println();
                con.println("File output:");
                con.print(a);
            }
            left = true;
            for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;
            if (left) con.println("...");
            else con.println();
            con.println("Time passed:  " + (finishTime - startTime) / 1000000000.0 + " sec");
            con.println("Memory used:  " + (finishMem - startMem) + " bytes");
            con.println("Total memory: " + Runtime.getRuntime().totalMemory() + " bytes");
        }
    }

    boolean tick(double x) {
        if (System.nanoTime() - tempTime > x) {
            tempTime = System.nanoTime();
            con.println("Tick at " + (tempTime - startTime) / 1000000000 + " sec");
            con.print("   ");
            return true;
        }
        return false;
    }

    void printTime() {
        con.println((System.nanoTime() - tempTime) + " nanos passed");
        tempTime = System.nanoTime();
    }

    static boolean debugMode = false;
    PrintStream con = System.out;

    void init() throws IOException {
        if (debugMode) {
            br = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"));
        } else
            switch (IOMode) {
                case 0:
                    br = new BufferedReader(new InputStreamReader(System.in));
                    out = new PrintWriter(System.out);
                    break;
                case 1:
                    br = new BufferedReader(new FileReader(taskName + ".in"));
                    out = new PrintWriter(new FileWriter(taskName + ".out"));
                    break;
                case 2:
                    br = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter(new FileWriter("output.txt"));
                    break;
                case 3:
                    out = new PrintWriter(new FileWriter("input.txt"));
                    break;
            }
    }

    BufferedReader br;
    PrintWriter out;
    StringTokenizer in;

    boolean hasMoreTokens() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) return false;
            in = new StringTokenizer(line);
        }
        return true;
    }

    String nextString() throws IOException {
        return hasMoreTokens() ? in.nextToken() : null;
    }

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

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

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


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

//created at 7:44 PM 10/13/11 by Abrackadabra

public class C {
    int IOMode = 0; //0 - consoleIO, 1 - <taskName>.in/out, 2 - input.txt/output.txt, 3 - test case generator
    String taskName = "";

    void solve() throws IOException {
        int n = Integer.parseInt(nextString()), m = Integer.parseInt(nextString());
        String s = nextString();
        int min = 1000000;
        int[] best = new int[n];
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = s.charAt(i) - '0';
        for (int d = 0; d < 10; d++) {
            int[] b = new int[n];
            int c = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] != d)
                    c++;
                b[i] = a[i];
            }
            c = Math.max(m - (n - c), 0);
            int C = 0;
            for (int q = 1; q < 10; q++) {
                for (int i = 0; i < n; i++) {
                    if (c == 0) break;
                    if (b[i] == d + q) {
                        b[i] = d;
                        c--;
                        C += q;
                    }
                }
                for (int i = n - 1; i >= 0; i--) {
                    if (c == 0) break;
                    if (b[i] == d - q) {
                        b[i] = d;
                        c--;
                        C += q;
                    }
                }
            }
            if (C < min) {
                min = C;
                best = b;
            }
            if (C == min) {
                boolean ch = false;
                for (int i = 0; i < n; i++) {
                    if (b[i] < best[i]) {
                        ch = true;
                        break;
                    }
                    if (b[i] > best[i]) break;
                }
                if (ch) best = b;
            }
        }
        out.println(min);
        for (int i = 0; i < n; i++)
            out.print(best[i]);
    }

    public static void main(String[] args) throws IOException {
        if (args.length > 0 && args[0].equals("Abra")) debugMode = true;
        new C().run();
    }

    long startTime = System.nanoTime(), tempTime = startTime, finishTime = startTime;
    long startMem = Runtime.getRuntime().totalMemory(), finishMem = startMem;

    void run() throws IOException {
        init();
        if (debugMode) {
            con.println("Start");
            con.println("Console output:");
        }
        solve();
        finishTime = System.nanoTime();
        finishMem = Runtime.getRuntime().totalMemory();
        out.flush();
        if (debugMode) {
            int maxSymbols = 1000, c = 0;
            BufferedReader tbr = new BufferedReader(new FileReader("input.txt"));
            char[] a = new char[maxSymbols];
            tbr.read(a);
            if (a[0] != 0) {
                con.println();
                con.println("File input:");
                con.print(a);
            }
            boolean left = true;
            for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;
            if (left) con.println("...");
            else con.println();
            tbr = new BufferedReader(new FileReader("output.txt"));
            a = new char[maxSymbols];
            tbr.read(a);
            if (a[0] != 0) {
                con.println();
                con.println("File output:");
                con.print(a);
            }
            left = true;
            for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;
            if (left) con.println("...");
            else con.println();
            con.println("Time passed:  " + (finishTime - startTime) / 1000000000.0 + " sec");
            con.println("Memory used:  " + (finishMem - startMem) + " bytes");
            con.println("Total memory: " + Runtime.getRuntime().totalMemory() + " bytes");
        }
    }

    boolean tick(double x) {
        if (System.nanoTime() - tempTime > x) {
            tempTime = System.nanoTime();
            con.println("Tick at " + (tempTime - startTime) / 1000000000 + " sec");
            con.print("   ");
            return true;
        }
        return false;
    }

    void printTime() {
        con.println((System.nanoTime() - tempTime) + " nanos passed");
        tempTime = System.nanoTime();
    }

    static boolean debugMode = false;
    PrintStream con = System.out;

    void init() throws IOException {
        if (debugMode) {
            br = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"));
        } else
            switch (IOMode) {
                case 0:
                    br = new BufferedReader(new InputStreamReader(System.in));
                    out = new PrintWriter(System.out);
                    break;
                case 1:
                    br = new BufferedReader(new FileReader(taskName + ".in"));
                    out = new PrintWriter(new FileWriter(taskName + ".out"));
                    break;
                case 2:
                    br = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter(new FileWriter("output.txt"));
                    break;
                case 3:
                    out = new PrintWriter(new FileWriter("input.txt"));
                    break;
            }
    }

    BufferedReader br;
    PrintWriter out;
    StringTokenizer in;

    boolean hasMoreTokens() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) return false;
            in = new StringTokenizer(line);
        }
        return true;
    }

    String nextString() throws IOException {
        return hasMoreTokens() ? in.nextToken() : null;
    }

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

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

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


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

//created at 7:44 PM 10/13/11 by Abrackadabra

public class C {
    int IOMode = 0; //0 - consoleIO, 1 - <taskName>.in/out, 2 - input.txt/output.txt, 3 - test case generator
    String taskName = "";

    void solve() throws IOException {
        int n = Integer.parseInt(nextString()), m = Integer.parseInt(nextString());
        String s = nextString();
        int min = 1000000;
        int[] best = new int[n];
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = s.charAt(i) - '0';
        for (int d = 0; d < 10; d++) {
            int[] b = new int[n];
            int c = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] != d)
                    c++;
                b[i] = a[i];
            }
            c = Math.max(m - (n - c), 0);
            int C = 0;
            for (int q = 1; q < 10; q++) {
                for (int i = 0; i < n; i++) {
                    if (c == 0) break;
                    if (b[i] == d + q) {
                        b[i] = d;
                        c--;
                        C += q;
                    }
                }
                for (int i = 0; i < n; i++) {
                    if (c == 0) break;
                    if (b[i] == d - q) {
                        b[i] = d;
                        c--;
                        C += q;
                    }
                }
            }
            if (C < min) {
                min = C;
                best = b;
            }
        }
        out.println(min);
        for (int i = 0; i < n; i++)
            out.print(best[i]);
    }

    public static void main(String[] args) throws IOException {
        if (args.length > 0 && args[0].equals("Abra")) debugMode = true;
        new C().run();
    }

    long startTime = System.nanoTime(), tempTime = startTime, finishTime = startTime;
    long startMem = Runtime.getRuntime().totalMemory(), finishMem = startMem;

    void run() throws IOException {
        init();
        if (debugMode) {
            con.println("Start");
            con.println("Console output:");
        }
        solve();
        finishTime = System.nanoTime();
        finishMem = Runtime.getRuntime().totalMemory();
        out.flush();
        if (debugMode) {
            int maxSymbols = 1000, c = 0;
            BufferedReader tbr = new BufferedReader(new FileReader("input.txt"));
            char[] a = new char[maxSymbols];
            tbr.read(a);
            if (a[0] != 0) {
                con.println();
                con.println("File input:");
                con.print(a);
            }
            boolean left = true;
            for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;
            if (left) con.println("...");
            else con.println();
            tbr = new BufferedReader(new FileReader("output.txt"));
            a = new char[maxSymbols];
            tbr.read(a);
            if (a[0] != 0) {
                con.println();
                con.println("File output:");
                con.print(a);
            }
            left = true;
            for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;
            if (left) con.println("...");
            else con.println();
            con.println("Time passed:  " + (finishTime - startTime) / 1000000000.0 + " sec");
            con.println("Memory used:  " + (finishMem - startMem) + " bytes");
            con.println("Total memory: " + Runtime.getRuntime().totalMemory() + " bytes");
        }
    }

    boolean tick(double x) {
        if (System.nanoTime() - tempTime > x) {
            tempTime = System.nanoTime();
            con.println("Tick at " + (tempTime - startTime) / 1000000000 + " sec");
            con.print("   ");
            return true;
        }
        return false;
    }

    void printTime() {
        con.println((System.nanoTime() - tempTime) + " nanos passed");
        tempTime = System.nanoTime();
    }

    static boolean debugMode = false;
    PrintStream con = System.out;

    void init() throws IOException {
        if (debugMode) {
            br = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"));
        } else
            switch (IOMode) {
                case 0:
                    br = new BufferedReader(new InputStreamReader(System.in));
                    out = new PrintWriter(System.out);
                    break;
                case 1:
                    br = new BufferedReader(new FileReader(taskName + ".in"));
                    out = new PrintWriter(new FileWriter(taskName + ".out"));
                    break;
                case 2:
                    br = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter(new FileWriter("output.txt"));
                    break;
                case 3:
                    out = new PrintWriter(new FileWriter("input.txt"));
                    break;
            }
    }

    BufferedReader br;
    PrintWriter out;
    StringTokenizer in;

    boolean hasMoreTokens() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) return false;
            in = new StringTokenizer(line);
        }
        return true;
    }

    String nextString() throws IOException {
        return hasMoreTokens() ? in.nextToken() : null;
    }

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

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

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


import java.awt.Point;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class p118c {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int kk = in.nextInt();
        char[] num = in.next().toCharArray();

        int[] sum = new int[10];
        for (int i = 0; i < num.length; i++) {
            sum[num[i] - '0']++;
        }

        char[][] res = new char[10][num.length];
        for (int i = 0; i < res.length; i++) {
            for (int j = 0; j < res[i].length; j++) {
                res[i][j] = num[j];
            }
        }

        int[] money = new int[10];
        for (int i = 0; i < 10; i++) {
            int req = kk - sum[i];
            if (req <= 0) {
                req = 0;
            }
            int[] toBeChanged = new int[10];

            int tmp = 0;

            for (int j = i - 1, k = i + 1; j >= 0 || k < 10; j--, k++) {
                if (k < 10) {
                    int canGet = Math.min(req, sum[k]);

                    req -= canGet;
                    toBeChanged[k] = canGet;
                    tmp += (canGet) * Math.abs(k - i);
                }
                if (j >= 0) {
                    int canGet = Math.min(req, sum[j]);

                    req -= canGet;
                    toBeChanged[j] = canGet;
                    tmp += (canGet) * Math.abs(i - j);
                }
            }
            money[i] = tmp;
            for (int j = 0; j < num.length; j++) {
                if (num[j] - '0' > i && toBeChanged[num[j] - '0'] > 0) {
                    res[i][j] = (char) ('0' + i);
                    toBeChanged[num[j] - '0']--;
                }
            }
            for (int j = num.length - 1; j >= 0; j--) {
                if (num[j] - '0' < i && toBeChanged[num[j] - '0'] > 0) {
                    res[i][j] = (char) ('0' + i);
                    toBeChanged[num[j] - '0']--;
                }
            }
        }
        solution[] all = new solution[10];
        for (int i = 0; i < 10; i++) {
            all[i] = new solution(money[i], res[i]);
        }
        Arrays.sort(all);

        /*for (int i = 0; i < all.length; i++) {
            System.out.println("mon : " + all[i].money);
            for (int j = 0; j < all[i].sol.length; j++) {
                System.out.print(all[i].sol[j]);
            }
            System.out.println();
            System.out.println();
        }*/

        int min = all[0].money;
        boolean[] ok = new boolean[10];
        int oks = 0;
        for (int i = 0; i < ok.length; i++) {
            if (all[i].money == min) {
                ok[i] = true;
                oks++;
            }
        }
        System.out.println(min);
        for (int i = 0; i < n; i++) {
            if (oks == 1) {
                for (int j = 0; j < 10; j++) {
                    if (ok[j]) {
                        for (int k = 0; k < n; k++) {
                            System.out.print(all[j].sol[k]);
                        }
                        System.out.println();
                        return;
                    }
                }
            }
            int minDigit = 10;
            for (int j = 0; j < 10; j++) {
                if (ok[j]) {
                    minDigit = Math.min((int) (all[j].sol[i] - '0'), minDigit);
                }
            }
            for (int j = 0; j < 10; j++) {
                if (minDigit < (all[j].sol[i] - '0') && ok[j]) {
                    ok[j] = false;
                    oks--;
                }
            }
        }
        for (int i = 0; i < ok.length; i++) {
            if (ok[i]) {
                for (int k = 0; k < n; k++) {
                    System.out.print(all[i].sol[k]);
                }
                System.out.println();
                return;
            }
        }
    }
}

class solution implements Comparable<solution> {
    int money;
    char[] sol;

    public solution(int a, char[] r) {
        money = a;
        sol = r;
    }

    public int compareTo(solution o) {
        return money - o.money;
    }
}


import java.awt.Point;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class p118c {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int kk = in.nextInt();
        char[] num = in.next().toCharArray();

        int[] sum = new int[10];
        for (int i = 0; i < num.length; i++) {
            sum[num[i] - '0']++;
        }

        char[][] res = new char[10][num.length];
        for (int i = 0; i < res.length; i++) {
            for (int j = 0; j < res[i].length; j++) {
                res[i][j] = num[j];
            }
        }

        int[] money = new int[10];
        for (int i = 0; i < 10; i++) {
            int req = kk - sum[i];
            if (req <= 0) {
                req = 0;
            }
            int[] toBeChanged = new int[10];

            int tmp = 0;

            for (int j = i - 1, k = i + 1; j >= 0 || k < 10; j--, k++) {
                if (k < 10) {
                    int canGet = Math.min(req, sum[k]);

                    req -= canGet;
                    toBeChanged[k] = canGet;
                    tmp += (canGet) * Math.abs(k - i);
                }
                if (j >= 0) {
                    int canGet = Math.min(req, sum[j]);

                    req -= canGet;
                    toBeChanged[j] = canGet;
                    tmp += (canGet) * Math.abs(i - j);
                }
            }
            money[i] = tmp;
            for (int j = 0; j < num.length; j++) {
                if (num[j] - '0' > i && toBeChanged[num[j] - '0'] > 0) {
                    res[i][j] = (char) ('0' + i);
                    toBeChanged[num[j] - '0']--;
                }
            }
            for (int j = num.length - 1; j >= 0; j--) {
                if (num[j] - '0' < i && toBeChanged[num[j] - '0'] > 0) {
                    res[i][j] = (char) ('0' + i);
                    toBeChanged[num[j] - '0']--;
                }
            }
        }
        solution[] all = new solution[10];
        for (int i = 0; i < 10; i++) {
            all[i] = new solution(money[i], res[i]);
        }
        Arrays.sort(all);

        /*for (int i = 0; i < all.length; i++) {
            System.out.println("mon : " + all[i].money);
            for (int j = 0; j < all[i].sol.length; j++) {
                System.out.print(all[i].sol[j]);
            }
            System.out.println();
            System.out.println();
        }*/

        int min = all[0].money;
        boolean[] ok = new boolean[10];
        int oks = 0;
        for (int i = 0; i < ok.length; i++) {
            if (all[i].money == min) {
                ok[i] = true;
                oks++;
            }
        }
        System.out.println(min);
        for (int i = 0; i < n; i++) {
            if (oks == 1) {
                for (int j = 0; j < 10; j++) {
                    if (ok[j]) {
                        for (int k = 0; k < n; k++) {
                            System.out.print(all[j].sol[k]);
                        }
                        System.out.println();
                        return;
                    }
                }
            }
            int minDigit = 10;
            for (int j = 0; j < 10; j++) {
                if (ok[j]) {
                    minDigit = Math.min((int) (all[j].sol[i] - '0'), minDigit);
                }
            }
            for (int j = 0; j < 10; j++) {
                if (minDigit < (all[j].sol[i] - '0') && ok[j]) {
                    ok[j] = false;
                    oks--;
                }
            }
        }
    }
}

class solution implements Comparable<solution> {
    int money;
    char[] sol;

    public solution(int a, char[] r) {
        money = a;
        sol = r;
    }

    public int compareTo(solution o) {
        return money - o.money;
    }
}


import java.awt.Point;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class p118c {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int kk = in.nextInt();
		char[] num = in.next().toCharArray();

		int[] sum = new int[10];
		for (int i = 0; i < num.length; i++) {
			sum[num[i] - '0']++;
		}

		char[][] res = new char[10][num.length];
		for (int i = 0; i < res.length; i++) {
			for (int j = 0; j < res[i].length; j++) {
				res[i][j] = num[j];
			}
		}

		int[] money = new int[10];
		for (int i = 0; i < 10; i++) {
			int req = kk - sum[i];
			if (req <= 0) {
				money[i] = 0;
				continue;
			}
			int[] toBeChanged = new int[10];

			int tmp = 0;

			for (int j = i - 1, k = i + 1; j >= 0 || k < 10; j--, k++) {
				if (k < 10) {
					int canGet = Math.min(req, sum[k]);

					req -= canGet;
					toBeChanged[k] = canGet;
					tmp += (canGet) * Math.abs(k - i);
				}
				if (j >= 0) {
					int canGet = Math.min(req, sum[j]);

					req -= canGet;
					toBeChanged[j] = canGet;
					tmp += (canGet) * Math.abs(i - j);
				}
			}
			money[i] = tmp;
			for (int j = 0; j < num.length; j++) {
				if (num[j] - '0' > i && toBeChanged[num[j] - '0'] > 0) {
					res[i][j] = (char) ('0' + i);
					toBeChanged[num[j] - '0']--;
				}
			}
			for (int j = num.length - 1; j >= 0; j--) {
				if (num[j] - '0' < i && toBeChanged[num[j] - '0'] > 0) {
					res[i][j] = (char) ('0' + i);
					toBeChanged[num[j] - '0']--;
				}
			}
		}
		solution[] all = new solution[10];
		for (int i = 0; i < 10; i++) {
			all[i] = new solution(money[i], res[i]);
		}
		Arrays.sort(all);

		/*for (int i = 0; i < all.length; i++) {
			System.out.println("mon : " + all[i].money);
			for (int j = 0; j < all[i].sol.length; j++) {
				System.out.print(all[i].sol[j]);
			}
			System.out.println();
			System.out.println();
		}*/

		int min = all[0].money;
		boolean[] ok = new boolean[10];
		int oks = 0;
		for (int i = 0; i < ok.length; i++) {
			if (all[i].money == min) {
				ok[i] = true;
				oks++;
			}
		}
		System.out.println(min);
		for (int i = 0; i < n; i++) {
			if (oks == 1) {
				for (int j = 0; j < 10; j++) {
					if (ok[j]) {
						for (int k = 0; k < n; k++) {
							System.out.print(all[j].sol[k]);
						}
						System.out.println();
						return;
					}
				}
			}
			int minDigit = 10;
			for (int j = 0; j < 10; j++) {
				if (ok[j]) {
					minDigit = Math.min((int) (all[j].sol[i] - '0'), minDigit);
				}
			}
			for (int j = 0; j < 10; j++) {
				if (minDigit < (all[j].sol[i] - '0') && ok[j]) {
					ok[j] = false;
					oks--;
				}
			}
		}
	}
}

class solution implements Comparable<solution> {
	int money;
	char[] sol;

	public solution(int a, char[] r) {
		money = a;
		sol = r;
	}

	public int compareTo(solution o) {
		return money - o.money;
	}
}


import java.awt.Point;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class p118c {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int kk = in.nextInt();
        char[] num = in.next().toCharArray();

        int[] sum = new int[10];
        for (int i = 0; i < num.length; i++) {
            sum[num[i] - '0']++;
        }

        char[][] res = new char[10][num.length];
        for (int i = 0; i < res.length; i++) {
            for (int j = 0; j < res[i].length; j++) {
                res[i][j] = num[j];
            }
        }

        int[] money = new int[10];
        for (int i = 0; i < 10; i++) {
            int req = kk - sum[i];
            if (req <= 0) {
                money[i] = 0;
                System.out.println(0);
                for (int j = 0; j < num.length; j++) {
                    System.out.print(num[j]);
                }return;
            }
            int[] toBeChanged = new int[10];

            int tmp = 0;

            for (int j = i - 1, k = i + 1; j >= 0 || k < 10; j--, k++) {
                if (k < 10) {
                    int canGet = Math.min(req, sum[k]);

                    req -= canGet;
                    toBeChanged[k] = canGet;
                    tmp += (canGet) * Math.abs(k - i);
                }
                if (j >= 0) {
                    int canGet = Math.min(req, sum[j]);

                    req -= canGet;
                    toBeChanged[j] = canGet;
                    tmp += (canGet) * Math.abs(i - j);
                }
            }
            money[i] = tmp;
            for (int j = 0; j < num.length; j++) {
                if (num[j] - '0' > i && toBeChanged[num[j] - '0'] > 0) {
                    res[i][j] = (char) ('0' + i);
                    toBeChanged[num[j] - '0']--;
                }
            }
            for (int j = num.length - 1; j >= 0; j--) {
                if (num[j] - '0' < i && toBeChanged[num[j] - '0'] > 0) {
                    res[i][j] = (char) ('0' + i);
                    toBeChanged[num[j] - '0']--;
                }
            }
        }
        solution[] all = new solution[10];
        for (int i = 0; i < 10; i++) {
            all[i] = new solution(money[i], res[i]);
        }
        Arrays.sort(all);

        /*for (int i = 0; i < all.length; i++) {
            System.out.println("mon : " + all[i].money);
            for (int j = 0; j < all[i].sol.length; j++) {
                System.out.print(all[i].sol[j]);
            }
            System.out.println();
            System.out.println();
        }*/

        int min = all[0].money;
        boolean[] ok = new boolean[10];
        int oks = 0;
        for (int i = 0; i < ok.length; i++) {
            if (all[i].money == min) {
                ok[i] = true;
                oks++;
            }
        }
        System.out.println(min);
        for (int i = 0; i < n; i++) {
            if (oks == 1) {
                for (int j = 0; j < 10; j++) {
                    if (ok[j]) {
                        for (int k = 0; k < n; k++) {
                            System.out.print(all[j].sol[k]);
                        }
                        System.out.println();
                        return;
                    }
                }
            }
            int minDigit = 10;
            for (int j = 0; j < 10; j++) {
                if (ok[j]) {
                    minDigit = Math.min((int) (all[j].sol[i] - '0'), minDigit);
                }
            }
            for (int j = 0; j < 10; j++) {
                if (minDigit < (all[j].sol[i] - '0') && ok[j]) {
                    ok[j] = false;
                    oks--;
                }
            }
        }
    }
}

class solution implements Comparable<solution> {
    int money;
    char[] sol;

    public solution(int a, char[] r) {
        money = a;
        sol = r;
    }

    public int compareTo(solution o) {
        return money - o.money;
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class c89 {
    public static void debug(Object... obs) {
        System.out.println(Arrays.deepToString(obs));
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt();
        int k=sc.nextInt();

        int val=sc.nextInt();

        List<V>[]lists=new List[10];

        for(int i=0;i<10;i++)
        {
            int valt=val;
            int c=n;
            lists[i]=new ArrayList<V>();
            while(c > 0)
            {
                int z = valt%10;
                V va = new V(Math.abs(z-i),c,z);
                valt = valt/10;
                c--;
                lists[i].add(va);
            }
            Collections.sort(lists[i]);
        }

        int minv=Integer.MAX_VALUE;
        int ind = -1;
        String res=null;
        for(int j=0;j<10;j++)
        {
            int minvj = 0;
            for(int i=0;i<k;i++)
            {
                minvj += lists[j].get(i).co;
                lists[j].get(i).val = j;
                //debug(i,lists[j].get(i).co,lists[j].get(i).id,lists[j].get(i).val);
            }
            //debug(minvj,minv);

            if(minvj <= minv)
            {

                Collections.sort(lists[j],indord);
                StringBuilder f = new StringBuilder();
                for(V vvv : lists[j])
                {
                    f.append(vvv.val);
                }
                String nres = f.toString();

                if(minvj == minv)
                {
                    //debug(nres,res);
                    if(nres.compareTo(res) < 0)
                    {
                        ind = j;
                        minv = minvj;
                        res = nres;
                    }
                }
                else
                {
                    ind = j;
                    minv = minvj;
                    res = nres;
                }
            }

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

    }
    static final Comparator<V> indord = new Comparator<V>(){

        @Override
        public int compare(V o1, V o2) {

            return o1.id - o2.id;
        }
    };

    public static class V implements Comparable<V>
    {
        int co;
        int id;
        int val;
        public V(int co, int id,int val) {
            super();
            this.co = co;
            this.id = id;
            this.val = val;
        }
        public int compareTo(V arg0) {
            if(co - arg0.co == 0)
            {
                return id - arg0.id;
            }
            return co - arg0.co;
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class c89 {
    public static void debug(Object... obs) {
        System.out.println(Arrays.deepToString(obs));
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt();
        int k=sc.nextInt();

        String val=sc.next();

        List<V>[]lists=new List[11];

        for(int i=0;i<10;i++)
        {
            //int valt=val;
            int c=n;
            lists[i]=new ArrayList<V>();
            for(int j=0;j<n;j++)
            {
                int z = Integer.parseInt(val.substring(j,j+1));
                V va = new V(Math.abs(z-i),j,z);
                //valt = valt/10;
                //c--;
                lists[i].add(va);
            }
            Collections.sort(lists[i]);
        }

        int minv=Integer.MAX_VALUE;
        int ind = -1;
        String res="";
        for(int j=0;j<10;j++)
        {
            int minvj = 0;
            for(int i=0;i<k;i++)
            {
                minvj += lists[j].get(i).co;
                lists[j].get(i).val = j;
                //debug(i,lists[j].get(i).co,lists[j].get(i).id,lists[j].get(i).val);
            }
            //debug(minvj,minv);

            if(minvj <= minv)
            {

                Collections.sort(lists[j],indord);
                StringBuilder f = new StringBuilder();
                for(V vvv : lists[j])
                {
                    f.append(vvv.val);
                }
                String nres = f.toString();

                if(minvj == minv)
                {
                    //debug(nres,res);
                    if(nres.compareTo(res) < 0)
                    {
                        ind = j;
                        minv = minvj;
                        res = nres;
                    }
                }
                else
                {
                    ind = j;
                    minv = minvj;
                    res = nres;
                }
            }

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

    }
    static final Comparator<V> indord = new Comparator<V>(){

        @Override
        public int compare(V o1, V o2) {

            return o1.id - o2.id;
        }
    };

    public static class V implements Comparable<V>
    {
        int co;
        int id;
        int val;
        public V(int co, int id,int val) {
            super();
            this.co = co;
            this.id = id;
            this.val = val;
        }
        public int compareTo(V arg0) {
            if(co - arg0.co == 0)
            {
                if(val - arg0.val == 0)
                    return id - arg0.id;
                return val - arg0.val;
            }
            return co - arg0.co;
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class c89 {
    public static void debug(Object... obs) {
        System.out.println(Arrays.deepToString(obs));
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt();
        int k=sc.nextInt();

        String val=sc.next();

        List<V>[]lists=new List[11];

        for(int i=0;i<10;i++)
        {
            //int valt=val;
            int c=n;
            lists[i]=new ArrayList<V>();
            for(int j=0;j<n;j++)
            {
                int z = Integer.parseInt(val.substring(j,j+1));
                V va = new V(Math.abs(z-i),j,z,i);
                //valt = valt/10;
                //c--;
                lists[i].add(va);
            }
            Collections.sort(lists[i]);
        }

        int minv=Integer.MAX_VALUE;
        int ind = -1;
        String res="";
        for(int j=0;j<10;j++)
        {
            int minvj = 0;
            for(int i=0;i<k;i++)
            {
                minvj += lists[j].get(i).co;
                lists[j].get(i).val = j;
                //debug(i,lists[j].get(i).co,lists[j].get(i).id,lists[j].get(i).val);
            }
            //debug(minvj,minv);

            if(minvj <= minv)
            {

                Collections.sort(lists[j],indord);
                StringBuilder f = new StringBuilder();
                for(V vvv : lists[j])
                {
                    f.append(vvv.val);
                }
                String nres = f.toString();

                if(minvj == minv)
                {
                    //debug(nres,res);
                    if(nres.compareTo(res) < 0)
                    {
                        ind = j;
                        minv = minvj;
                        res = nres;
                    }
                }
                else
                {
                    ind = j;
                    minv = minvj;
                    res = nres;
                }
            }

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

    }
    static final Comparator<V> indord = new Comparator<V>(){

        @Override
        public int compare(V o1, V o2) {

            return o1.id - o2.id;
        }
    };

    public static class V implements Comparable<V>
    {
        int co;
        int id;
        int val;
        int ref;
        public V(int co, int id,int val, int ref) {
            super();
            this.co = co;
            this.id = id;
            this.val = val;
            this.ref = ref;
        }
        public int compareTo(V arg0) {
            if(co - arg0.co == 0)
            {
                if((val - ref) - (arg0.val - ref) == 0)
                    return (val - ref)*(id - arg0.id);
                return (arg0.val - ref) - (val - ref);
            }
            return co - arg0.co;
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class c89 {
    public static void debug(Object... obs) {
        System.out.println(Arrays.deepToString(obs));
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt();
        int k=sc.nextInt();

        String val=sc.next();

        List<V>[]lists=new List[11];

        for(int i=0;i<10;i++)
        {
            //int valt=val;
            int c=n;
            lists[i]=new ArrayList<V>();
            for(int j=0;j<n;j++)
            {
                int z = Integer.parseInt(val.substring(j,j+1));
                V va = new V(Math.abs(z-i),j,z);
                //valt = valt/10;
                //c--;
                lists[i].add(va);
            }
            Collections.sort(lists[i]);
        }

        int minv=Integer.MAX_VALUE;
        int ind = -1;
        String res="";
        for(int j=0;j<10;j++)
        {
            int minvj = 0;
            for(int i=0;i<k;i++)
            {
                minvj += lists[j].get(i).co;
                lists[j].get(i).val = j;
                //debug(i,lists[j].get(i).co,lists[j].get(i).id,lists[j].get(i).val);
            }
            //debug(minvj,minv);

            if(minvj <= minv)
            {

                Collections.sort(lists[j],indord);
                StringBuilder f = new StringBuilder();
                for(V vvv : lists[j])
                {
                    f.append(vvv.val);
                }
                String nres = f.toString();

                if(minvj == minv)
                {
                    debug(nres,res);
                    if(nres.compareTo(res) < 0)
                    {
                        ind = j;
                        minv = minvj;
                        res = nres;
                    }
                }
                else
                {
                    ind = j;
                    minv = minvj;
                    res = nres;
                }
            }

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

    }
    static final Comparator<V> indord = new Comparator<V>(){

        @Override
        public int compare(V o1, V o2) {

            return o1.id - o2.id;
        }
    };

    public static class V implements Comparable<V>
    {
        int co;
        int id;
        int val;
        public V(int co, int id,int val) {
            super();
            this.co = co;
            this.id = id;
            this.val = val;
        }
        public int compareTo(V arg0) {
            if(co - arg0.co == 0)
            {
                if(- val + arg0.val == 0)
                    return -id + arg0.id;
                return - val + arg0.val;
            }
            return co - arg0.co;
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class c89 {
    public static void debug(Object... obs) {
        System.out.println(Arrays.deepToString(obs));
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt();
        int k=sc.nextInt();

        String val=sc.next();

        List<V>[]lists=new List[11];

        for(int i=0;i<10;i++)
        {
            //int valt=val;
            int c=n;
            lists[i]=new ArrayList<V>();
            for(int j=0;j<n;j++)
            {
                int z = Integer.parseInt(val.substring(j,j+1));
                V va = new V(Math.abs(z-i),j,z);
                //valt = valt/10;
                //c--;
                lists[i].add(va);
            }
            Collections.sort(lists[i]);
        }

        int minv=Integer.MAX_VALUE;
        int ind = -1;
        String res="";
        for(int j=0;j<10;j++)
        {
            int minvj = 0;
            for(int i=0;i<k;i++)
            {
                minvj += lists[j].get(i).co;
                lists[j].get(i).val = j;
                //debug(i,lists[j].get(i).co,lists[j].get(i).id,lists[j].get(i).val);
            }
            //debug(minvj,minv);

            if(minvj <= minv)
            {

                Collections.sort(lists[j],indord);
                StringBuilder f = new StringBuilder();
                for(V vvv : lists[j])
                {
                    f.append(vvv.val);
                }
                String nres = f.toString();

                if(minvj == minv)
                {
                    //debug(nres,res);
                    if(nres.compareTo(res) < 0)
                    {
                        ind = j;
                        minv = minvj;
                        res = nres;
                    }
                }
                else
                {
                    ind = j;
                    minv = minvj;
                    res = nres;
                }
            }

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

    }
    static final Comparator<V> indord = new Comparator<V>(){

        @Override
        public int compare(V o1, V o2) {

            return o1.id - o2.id;
        }
    };

    public static class V implements Comparable<V>
    {
        int co;
        int id;
        int val;
        public V(int co, int id,int val) {
            super();
            this.co = co;
            this.id = id;
            this.val = val;
        }
        public int compareTo(V arg0) {
            if(co - arg0.co == 0)
            {
                if(- val + arg0.val == 0)
                    return -id + arg0.id;
                return - val + arg0.val;
            }
            return co - arg0.co;
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class c89 {
    public static void debug(Object... obs) {
        System.out.println(Arrays.deepToString(obs));
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt();
        int k=sc.nextInt();

        String val=sc.next();

        List<V>[]lists=new List[11];

        for(int i=0;i<10;i++)
        {
            //int valt=val;
            int c=n;
            lists[i]=new ArrayList<V>();
            for(int j=0;j<n;j++)
            {
                int z = Integer.parseInt(val.substring(j,j+1));
                V va = new V(Math.abs(z-i),j,z);
                //valt = valt/10;
                //c--;
                lists[i].add(va);
            }
            Collections.sort(lists[i]);
        }

        int minv=Integer.MAX_VALUE;
        int ind = -1;
        String res="";
        for(int j=0;j<10;j++)
        {
            int minvj = 0;
            for(int i=0;i<k;i++)
            {
                minvj += lists[j].get(i).co;
                lists[j].get(i).val = j;
                //debug(i,lists[j].get(i).co,lists[j].get(i).id,lists[j].get(i).val);
            }
            //debug(minvj,minv);

            if(minvj <= minv)
            {

                Collections.sort(lists[j],indord);
                StringBuilder f = new StringBuilder();
                for(V vvv : lists[j])
                {
                    f.append(vvv.val);
                }
                String nres = f.toString();

                if(minvj == minv)
                {
                    //debug(nres,res);
                    if(nres.compareTo(res) < 0)
                    {
                        ind = j;
                        minv = minvj;
                        res = nres;
                    }
                }
                else
                {
                    ind = j;
                    minv = minvj;
                    res = nres;
                }
            }

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

    }
    static final Comparator<V> indord = new Comparator<V>(){

        @Override
        public int compare(V o1, V o2) {

            return o1.id - o2.id;
        }
    };

    public static class V implements Comparable<V>
    {
        int co;
        int id;
        int val;
        public V(int co, int id,int val) {
            super();
            this.co = co;
            this.id = id;
            this.val = val;
        }
        public int compareTo(V arg0) {
            if(co - arg0.co == 0)
            {
                return id - arg0.id;
            }
            return co - arg0.co;
        }
    }
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		in.nextLine();
		final int[] d = new int[n], c = new int[10];
		Integer[]  z = new Integer[n], z2 = new Integer[n];
		String t = in.nextLine();
		for (int i = 0; i < n; i++) {
			d[i] = (int)(t.charAt(i) - '0');
			c[d[i]]++;
			z2[i]=i;
		}

		for (int i = 0; i < 10; i++) {
			if (c[i]>=k) {
				System.out.println(0);
				System.out.println(t);
				return;
			}
		}
		int[] b1 = new int[n];
		int min = 10000000, b3=0, sa1=0, sa2=0;
		for (int i = 0; i < 10; i++) {
			System.arraycopy(z2,  0, z, 0, n);
			final int j = i;
			Arrays.sort(z, new Comparator<Integer>() {

				@Override
				public int compare(Integer o1, Integer o2) {
					int d1 = Math.abs(d[o1]-j);
					int d2 = Math.abs(d[o2]-j);
					if (d1==d2) return o2-o1;
					return d1-d2;
				}
			});
			int s = 0;
			for (int q = 0; q < k; q++) s+=Math.abs(d[z[q]]-i);
			if (s<=min) {
				boolean sh = false;
				int a1 = n+1 ,a2 = n+1;
				for (int x = 0; x < k; x++) {
					if (d[z[x]]>i) {if (x < a1) a1=x;}
					else if(d[z[x]]<i && x < a2) a2=x;
				}
				if (s <min  || a1<sa1 || (a1==n+1&&sa1==n+1&&a2>sa2)) {
						for (int y = 0; y < n; y++) b1[y]= z[y];
						b3 = i;
						min=s;
						sa1=a1;
						sa2=a2;
					}

			}
		}
		System.out.println(min);
		for (int i = 0; i < k; i++) {
			d[b1[i]]=b3;
		}
		for (int i = 0; i < n; i++) System.out.print((char)('0'+d[i]));
		System.out.println();
	}
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		in.nextLine();
		final int[] d = new int[n], c = new int[10];
		Integer[]  z = new Integer[n], z2 = new Integer[n];
		String t = in.nextLine();
		for (int i = 0; i < n; i++) {
			d[i] = (int)(t.charAt(i) - '0');
			c[d[i]]++;
			z2[i]=i;
		}

		for (int i = 0; i < 10; i++) {
			if (c[i]>=k) {
				System.out.println(0);
				System.out.println(t);
				return;
			}
		}
		int[] b1 = new int[n];
		int min = 10000000, b3=0;
		for (int i = 0; i < 10; i++) {
			System.arraycopy(z2,  0, z, 0, n);
			final int j = i;
			Arrays.sort(z, new Comparator<Integer>() {

				@Override
				public int compare(Integer o1, Integer o2) {
					int d1 = Math.abs(d[o1]-j);
					int d2 = Math.abs(d[o2]-j);
					if (d1==d2) return d[o2]-d[o1];
					return d1-d2;
				}
			});
			int s = 0;
			for (int q = 0; q < k; q++) s+=Math.abs(d[z[q]]-i);
			if (s<min) {
				for (int y = 0; y < n; y++) b1[y]= z[y];
				b3 = i;
				min=s;
			}
		}
		System.out.println(min);
		for (int i = 0; i < k; i++) {
			d[b1[i]]=b3;
		}
		for (int i = 0; i < n; i++) System.out.print((char)('0'+d[i]));
		System.out.println();
	}
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		in.nextLine();
		final int[] d = new int[n], c = new int[10];
		Integer[]  z = new Integer[n], z2 = new Integer[n];
		String t = in.nextLine();
		for (int i = 0; i < n; i++) {
			d[i] = (int)(t.charAt(i) - '0');
			c[d[i]]++;
			z2[i]=i;
		}

		for (int i = 0; i < 10; i++) {
			if (c[i]>=k) {
				System.out.println(0);
				System.out.println(t);
				return;
			}
		}
		int[] b1 = new int[n];
		int min = 10000000, b3=0, sa1=0, sa2=0;
		for (int i = 0; i < 10; i++) {
			System.arraycopy(z2,  0, z, 0, n);
			final int j = i;
			Arrays.sort(z, new Comparator<Integer>() {

				@Override
				public int compare(Integer o1, Integer o2) {
					int d1 = Math.abs(d[o1]-j);
					int d2 = Math.abs(d[o2]-j);
					if (d1==d2) {
						if (d[o1] != d[o2]) return d[o2]-d[o1];
						if (o1>j) return o1-o2;
						if (o1<j) return o2-o1;
						return 0;
					}
					return d1-d2;
				}
			});
			int s = 0;
			for (int q = 0; q < k; q++) s+=Math.abs(d[z[q]]-i);
			if (s<=min) {
				int a1 = n+1 ,a2 = n+1;
				for (int x = 0; x < k; x++) {
					if (d[z[x]]>i) {if (x < a1) a1=x;}
					else if(d[z[x]]<i && x < a2) a2=x;
				}
				if (s <min  || (a1<sa1 && a2 > a1) || (a2>sa2 && sa1 > sa2) ) {
						for (int y = 0; y < n; y++) b1[y]= z[y];
						b3 = i;
						min=s;
						sa1=a1;
						sa2=a2;
					}

			}
		}
		System.out.println(min);
		for (int i = 0; i < k; i++) {
			d[b1[i]]=b3;
		}
		for (int i = 0; i < n; i++) System.out.print((char)('0'+d[i]));
		System.out.println();
	}
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		in.nextLine();
		final int[] d = new int[n], c = new int[10];
		Integer[]  z = new Integer[n], z2 = new Integer[n];
		String t = in.nextLine();
		for (int i = 0; i < n; i++) {
			d[i] = (int)(t.charAt(i) - '0');
			c[d[i]]++;
			z2[i]=i;
		}

		for (int i = 0; i < 10; i++) {
			if (c[i]>=k) {
				System.out.println(0);
				System.out.println(t);
				return;
			}
		}
		int[] b1 = new int[n];
		int min = 10000000, b3=0, sa1=0, sa2=0;
		for (int i = 0; i < 10; i++) {
			System.arraycopy(z2,  0, z, 0, n);
			final int j = i;
			Arrays.sort(z, new Comparator<Integer>() {

				@Override
				public int compare(Integer o1, Integer o2) {
					int d1 = Math.abs(d[o1]-j);
					int d2 = Math.abs(d[o2]-j);
					if (d1==d2) {
						if (d[o1] != d[o2]) return d[o2]-d[o1];
						if (d[o1]>j) return o1-o2;
						if (d[o1]<j) return o2-o1;
						return 0;
					}
					return d1-d2;
				}
			});
			int s = 0;
			for (int q = 0; q < k; q++) s+=Math.abs(d[z[q]]-i);
			if (s<=min) {
				int a1 = n+1 ,a2 = n+1;
				for (int x = 0; x < k; x++) {
					if (d[z[x]]>i) {if (x < a1) a1=x;}
					else if(d[z[x]]<i && x < a2) a2=x;
				}
				int ss = Math.min(sa1, Math.min(sa2, Math.min(a1, a2)));

				if (s <min  || !(ss==sa1 || ss == a2)) {
						for (int y = 0; y < n; y++) b1[y]= z[y];
						b3 = i;
						min=s;
						sa1=a1;
						sa2=a2;
					}

			}
		}
		System.out.println(min);
		for (int i = 0; i < k; i++) {
			d[b1[i]]=b3;
		}
		for (int i = 0; i < n; i++) System.out.print((char)('0'+d[i]));
		System.out.println();
	}
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		in.nextLine();
		final int[] d = new int[n], c = new int[10];
		Integer[]  z = new Integer[n], z2 = new Integer[n];
		String t = in.nextLine();
		for (int i = 0; i < n; i++) {
			d[i] = (int)(t.charAt(i) - '0');
			c[d[i]]++;
			z2[i]=i;
		}

		for (int i = 0; i < 10; i++) {
			if (c[i]>=k) {
				System.out.println(0);
				System.out.println(t);
				return;
			}
		}
		int[] b1 = new int[n];
		int min = 10000000, b3=0, sa1=0, sa2=0;
		for (int i = 0; i < 10; i++) {
			System.arraycopy(z2,  0, z, 0, n);
			final int j = i;
			Arrays.sort(z, new Comparator<Integer>() {

				@Override
				public int compare(Integer o1, Integer o2) {
					int d1 = Math.abs(d[o1]-j);
					int d2 = Math.abs(d[o2]-j);
					if (d1==d2) {
						if (d[o1] != d[o2]) return d[o2]-d[o1];
						if (d[o1]>j) return o1-o2;
						if (d[o1]<j) return o2-o1;
						return 0;
					}
					return d1-d2;
				}
			});
			int s = 0;
			for (int q = 0; q < k; q++) s+=Math.abs(d[z[q]]-i);
			if (s<=min) {
				int a1 = n+1 ,a2 = n+1;
				for (int x = 0; x < k; x++) {
					if (d[z[x]]>i) {if (z[x] < a1) a1=z[x];}
					else if(d[z[x]]<i && z[x] < a2) a2=z[x];
				}
				int ss = Math.min(sa1, Math.min(sa2, Math.min(a1, a2)));

				if (s <min  || !(ss==sa1 || ss == a2)) {
						for (int y = 0; y < n; y++) b1[y]= z[y];
						b3 = i;
						min=s;
						sa1=a1;
						sa2=a2;
					}

			}
		}
		System.out.println(min);
		for (int i = 0; i < k; i++) {
			d[b1[i]]=b3;
		}
		for (int i = 0; i < n; i++) System.out.print((char)('0'+d[i]));
		System.out.println();
	}
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		in.nextLine();
		final int[] d = new int[n], c = new int[10];
		Integer[]  z = new Integer[n], z2 = new Integer[n];
		String t = in.nextLine();
		for (int i = 0; i < n; i++) {
			d[i] = (int)(t.charAt(i) - '0');
			c[d[i]]++;
			z2[i]=i;
		}

		for (int i = 0; i < 10; i++) {
			if (c[i]>=k) {
				System.out.println(0);
				System.out.println(t);
				return;
			}
		}
		int[] b1 = new int[n];
		int min = 10000000, b3=0, sa1=0, sa2=0;
		for (int i = 0; i < 10; i++) {
			System.arraycopy(z2,  0, z, 0, n);
			final int j = i;
			Arrays.sort(z, new Comparator<Integer>() {

				@Override
				public int compare(Integer o1, Integer o2) {
					int d1 = Math.abs(d[o1]-j);
					int d2 = Math.abs(d[o2]-j);
					if (d1==d2) {
						if (d[o1] != d[o2]) return d[o2]-d[o1];
						if (o1>j) return o1-o2;
						if (o1<j) return o2-o1;
						return 0;
					}
					return d1-d2;
				}
			});
			int s = 0;
			for (int q = 0; q < k; q++) s+=Math.abs(d[z[q]]-i);
			if (s<=min) {
				boolean sh = false;
				int a1 = n+1 ,a2 = n+1;
				for (int x = 0; x < k; x++) {
					if (d[z[x]]>i) {if (x < a1) a1=x;}
					else if(d[z[x]]<i && x < a2) a2=x;
				}
				if (s <min  || a1<sa1 || (a1==n+1&&sa1==n+1&&a2>sa2)) {
						for (int y = 0; y < n; y++) b1[y]= z[y];
						b3 = i;
						min=s;
						sa1=a1;
						sa2=a2;
					}

			}
		}
		System.out.println(min);
		for (int i = 0; i < k; i++) {
			d[b1[i]]=b3;
		}
		for (int i = 0; i < n; i++) System.out.print((char)('0'+d[i]));
		System.out.println();
	}
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		in.nextLine();
		final int[] d = new int[n], c = new int[10];
		Integer[]  z = new Integer[n], z2 = new Integer[n];
		String t = in.nextLine();
		for (int i = 0; i < n; i++) {
			d[i] = (int)(t.charAt(i) - '0');
			c[d[i]]++;
			z2[i]=i;
		}

		for (int i = 0; i < 10; i++) {
			if (c[i]>=k) {
				System.out.println(0);
				System.out.println(t);
				return;
			}
		}
		int[] b1 = new int[n];
		int min = 10000000, b3=0, sa1=0, sa2=0;
		for (int i = 0; i < 10; i++) {
			System.arraycopy(z2,  0, z, 0, n);
			final int j = i;
			Arrays.sort(z, new Comparator<Integer>() {

				@Override
				public int compare(Integer o1, Integer o2) {
					int d1 = Math.abs(d[o1]-j);
					int d2 = Math.abs(d[o2]-j);
					if (d1==d2) {
						if (d[o1] != d[o2]) return d[o2]-d[o1];
						if (o1>j) return o1-o2;
						if (o1<j) return o2-o1;
						return 0;
					}
					return d1-d2;
				}
			});
			int s = 0;
			for (int q = 0; q < k; q++) s+=Math.abs(d[z[q]]-i);
			if (s<=min) {
				int a1 = n+1 ,a2 = n+1;
				for (int x = 0; x < k; x++) {
					if (d[z[x]]>i) {if (x < a1) a1=x;}
					else if(d[z[x]]<i && x < a2) a2=x;
				}
				int ss = Math.min(sa1, Math.min(sa2, Math.min(a1, a2)));

				if (s <min  || !(ss==sa1 || ss == a2)) {
						for (int y = 0; y < n; y++) b1[y]= z[y];
						b3 = i;
						min=s;
						sa1=a1;
						sa2=a2;
					}

			}
		}
		System.out.println(min);
		for (int i = 0; i < k; i++) {
			d[b1[i]]=b3;
		}
		for (int i = 0; i < n; i++) System.out.print((char)('0'+d[i]));
		System.out.println();
	}
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		in.nextLine();
		final int[] d = new int[n], c = new int[10];
		Integer[]  z = new Integer[n], z2 = new Integer[n];
		String t = in.nextLine();
		for (int i = 0; i < n; i++) {
			d[i] = (int)(t.charAt(i) - '0');
			c[d[i]]++;
			z2[i]=i;
		}

		for (int i = 0; i < 10; i++) {
			if (c[i]>=k) {
				System.out.println(0);
				System.out.println(t);
				return;
			}
		}
		int[] b1 = new int[n];
		int min = 10000000, b3=0, sa1=0, sa2=0;
		for (int i = 0; i < 10; i++) {
			System.arraycopy(z2,  0, z, 0, n);
			final int j = i;
			Arrays.sort(z, new Comparator<Integer>() {

				@Override
				public int compare(Integer o1, Integer o2) {
					int d1 = Math.abs(d[o1]-j);
					int d2 = Math.abs(d[o2]-j);
					if (d1==d2) {
						if (!o1.equals(o2)) return o2-o1;
						if (o1>j) return o1-o2;
						if (o1<j) return o2-o1;
						return 0;
					}
					return d1-d2;
				}
			});
			int s = 0;
			for (int q = 0; q < k; q++) s+=Math.abs(d[z[q]]-i);
			if (s<=min) {
				boolean sh = false;
				int a1 = n+1 ,a2 = n+1;
				for (int x = 0; x < k; x++) {
					if (d[z[x]]>i) {if (x < a1) a1=x;}
					else if(d[z[x]]<i && x < a2) a2=x;
				}
				if (s <min  || a1<sa1 || (a1==n+1&&sa1==n+1&&a2>sa2)) {
						for (int y = 0; y < n; y++) b1[y]= z[y];
						b3 = i;
						min=s;
						sa1=a1;
						sa2=a2;
					}

			}
		}
		System.out.println(min);
		for (int i = 0; i < k; i++) {
			d[b1[i]]=b3;
		}
		for (int i = 0; i < n; i++) System.out.print((char)('0'+d[i]));
		System.out.println();
	}
}


import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Vector;

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int k = in.nextInt();
        in.nextLine();

        String s = in.nextLine();

        Vector<Character> ans = new Vector<Character>();
        Vector<Character> fin_ans = new Vector<Character>();

        int min = Integer.MAX_VALUE;

        for (int i = 0; i <= 9; i++) {
            ans.clear();
            int money = 0;
            for (int j = 0; j < s.length(); j++) {
                ans.add(s.charAt(j));
            }

            int count = 0;
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) - '0' == i)
                    count++;
            }

            if (count >= k) {
                money = 0;
            } else {
                int rem = k - count;
                for (int j = 1; j <= 9; j++) {
                    if (i + j <= 9) {
                        for (int m = 0; m < s.length(); m++) {
                            if (s.charAt(m) - '0' == i + j) {
                                ans.set(m, (char) (i + '0'));
                                rem--;
                                money += j;
                                if (rem == 0)
                                    break;
                            }
                        }
                    }
                    if (rem == 0)
                        break;

                    if (i - j >= 0) {
                        for (int m = s.length() - 1; m >= 0; m--) {
                            if (s.charAt(m) - '0' == i - j) {
                                ans.set(m, (char) (i + '0'));
                                rem--;
                                money += j;
                                if (rem == 0)
                                    break;
                            }
                        }
                    }
                    if (rem == 0)
                        break;
                }
            }
            if (money < min) {
                min = money;
                fin_ans = (Vector<Character>) ans.clone();
            } else if (money == min) {
                if (isLower(ans, fin_ans))
                    fin_ans = (Vector<Character>) ans.clone();
            }
        }

        out.println(min);
        for (Character c : fin_ans) {
            out.print(c);
        }

        out.close();
    }

    private static boolean isLower(Vector<Character> v1, Vector<Character> v2) {
        for (int i = 0; i < v1.size(); i++) {
            if (v1.elementAt(i) < v2.elementAt(i))
                return true;
            else if (v1.elementAt(i) > v2.elementAt(i))
                return false;
        }
        return false;
    }
}


import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Vector;

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int k = in.nextInt();
        in.nextLine();

        String s = in.nextLine();

        Vector<Character> ans = new Vector<Character>();
        Vector<Character> fin_ans = new Vector<Character>();

        int min = Integer.MAX_VALUE;

        for (int i = 0; i <= 9; i++) {
            ans.clear();
            int money = 0;
            for (int j = 0; j < s.length(); j++) {
                ans.add(s.charAt(j));
            }

            int count = 0;
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) - '0' == i)
                    count++;
            }

            if (count >= k) {
                money = 0;
            } else {
                int rem = k - count;
                for (int j = 1; j <= 9; j++) {
                    if (i - j >= 0) {
                        for (int m = 0; m < s.length(); m++) {
                            if (s.charAt(m) - '0' == i - j) {
                                ans.set(m, (char) (i + '0'));
                                rem--;
                                money += j;
                                if (rem == 0)
                                    break;
                            }
                        }
                    }
                    if (rem == 0)
                        break;

                    if (i + j <= 9) {
                        for (int m = s.length() - 1; m >= 0; m--) {
                            if (s.charAt(m) - '0' == i + j) {
                                ans.set(m, (char) (i + '0'));
                                rem--;
                                money += j;
                                if (rem == 0)
                                    break;
                            }
                        }
                    }
                    if (rem == 0)
                        break;
                }
            }
            if (money < min) {
                min = money;
                fin_ans = (Vector<Character>) ans.clone();
            }
        }

        out.println(min);
        for (Character c : fin_ans) {
            out.print(c);
        }

        out.close();
    }
}


import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Vector;

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int k = in.nextInt();
        in.nextLine();

        String s = in.nextLine();

        Vector<Character> ans = new Vector<Character>();
        Vector<Character> fin_ans = new Vector<Character>();

        int min = Integer.MAX_VALUE;

        for (int i = 0; i <= 9; i++) {
            ans.clear();
            int money = 0;
            for (int j = 0; j < s.length(); j++) {
                ans.add(s.charAt(j));
            }

            int count = 0;
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) - '0' == i)
                    count++;
            }

            if (count >= k) {
                money = 0;
            } else {
                int rem = k - count;
                for (int j = 1; j <= 9; j++) {
                    if (i + j <= 9) {
                        for (int m = 0; m < s.length(); m++) {
                            if (s.charAt(m) - '0' == i + j) {
                                ans.set(m, (char) (i + '0'));
                                rem--;
                                money += j;
                                if (rem == 0)
                                    break;
                            }
                        }
                    }
                    if (rem == 0)
                        break;

                    if (i - j >= 0) {
                        for (int m = s.length() - 1; m >= 0; m--) {
                            if (s.charAt(m) - '0' == i - j) {
                                ans.set(m, (char) (i + '0'));
                                rem--;
                                money += j;
                                if (rem == 0)
                                    break;
                            }
                        }
                    }
                    if (rem == 0)
                        break;
                }
            }
            if (money < min) {
                min = money;
                fin_ans = (Vector<Character>) ans.clone();
            }
        }

        out.println(min);
        for (Character c : fin_ans) {
            out.print(c);
        }

        out.close();
    }
}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

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

    void run() throws Exception{
        Scanner sc = new Scanner(System.in);
        //BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
        // only sc.readLine() is available
        int N = sc.nextInt();
        int K = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int[] freq = new int[10];
        for(char c : s)freq[c-'0']++;
        int mn = 1<<30;
        char[] ans = "ERROR".toCharArray();
        for(int d = 0; d < 10; d++){
            int sum = freq[d];
            int[] need = new int[10];
            for(int i = 1; i <= 10 && sum < K; i++){
                if(d+i < 10){
                    int dif = min(freq[d+i], K-sum);
                    sum += dif;
                    need[d+i] += dif;
                }
                if(d-i >= 0){
                    int dif = min(freq[d-i], K-sum);
                    sum += dif;
                    need[d-i] += dif;
                }
            }
            int cost = 0;
            char[] t = new char[s.length];
            for(int i = 0; i < t.length; i++)t[i] = s[i];
            char a = (char)('0' + d);
            for(int i = 0; i < d; i++){
                char c = (char)('0' + i);
                cost += need[i] * abs(d-i);
                for(int j = t.length-1; j >= 0 && need[i] > 0; j--){
                    if(s[j] == c){
                        t[j] = a;
                        need[i]--;
                    }
                }
            }
            for(int i = d+1; i < 10; i++){
                char c = (char)('0' + i);
                cost += need[i] * abs(d-i);
                for(int j = 0; j < t.length && need[i] > 0; j++){
                    if(s[j] == c){
                        t[j] = a;
                        need[i]--;
                    }
                }
            }
            if(cost < mn){
                mn = cost;
                ans = t;
            }else if(cost == mn){
                boolean change = false;
                for(int i = 0; i < ans.length; i++)
                    if(t[i] != ans[i]){
                        if(t[i] < ans[i])change = true;
                        break;
                    }
                if(change)ans = t;
            }
        }
        System.out.println(mn);
        System.out.println(new String(ans));
    }
}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

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

    void run() throws Exception{
        Scanner sc = new Scanner(System.in);
        //BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
        // only sc.readLine() is available
        int N = sc.nextInt();
        int K = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int[] freq = new int[10];
        for(char c : s)freq[c-'0']++;
        int mn = 1<<30;
        char[] ans = "ERROR".toCharArray();
        for(int d = 0; d < 10; d++){
            int sum = freq[d];
            int[] need = new int[10];
            for(int i = 1; i <= 10 && sum < K; i++){
                if(d-i >= 0){
                    int dif = min(freq[d-i], K-sum);
                    sum += dif;
                    need[d-i] += dif;
                }
                if(d+i < 10){
                    int dif = min(freq[d+i], K-sum);
                    sum += dif;
                    need[d+i] += dif;
                }
            }
            int cost = 0;
            char[] t = new char[s.length];
            for(int i = 0; i < t.length; i++)t[i] = s[i];
            char a = (char)('0' + d);
            for(int i = 0; i < d; i++){
                char c = (char)('0' + i);
                cost += need[i] * abs(d-i);
                for(int j = t.length-1; j >= 0 && need[i] > 0; j--){
                    if(s[j] == c){
                        t[j] = a;
                        need[i]--;
                    }
                }
            }
            for(int i = d+1; i < 10; i++){
                char c = (char)('0' + i);
                cost += need[i] * abs(d-i);
                for(int j = 0; j < t.length && need[i] > 0; j++){
                    if(s[j] == c){
                        t[j] = a;
                        need[i]--;
                    }
                }
            }
            if(cost < mn){
                mn = cost;
                ans = t;
            }
        }
        System.out.println(mn);
        System.out.println(new String(ans));
    }
}