import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
//一个小错误,10的6次方是7位数,所以最大值是6*9=54
int[] path = new int[60]; // 这个这个是标记list数组当前存储了几个数字
int[][] list = new int[60][500000]; //存储数字 1000000个数字
for(int i = 1 ; i<= n ;i++){
int sum = 0;
int b = i;
while(b!=0){ //分解
int t = b%10;
sum+=t;
b/=10;
}
list[sum][path[sum]] = i; //直接赋值
path[sum] ++; //当前的数字位数加一
}
for(int i = 1; i<=54;i++){
if(m<=path[i]){
System.out.println(list[i][m-1]);
return;
}
m-= path[i];
}
}
}