import java.util.;
import java.io.;
public class Main{
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int m = Integer.parseInt(br.readLine());
int[] nums = new int[n];
for(int i = 0;i < n; i){
nums[i] = i + 1;
}
quickSort(nums,0,n - 1);
System.out.print(nums[m - 1]);
}
public static void quickSort(int[] nums,int left,int right){
int i = left - 1;
int j = right + 1;
int mid = getValue(nums[(left + (right - left) / 2)]);
int target = nums[(left + (right - left) / 2)];
if(left < right){
while(i < j){
do{
i;
}while((getValue(nums[i]) < mid) || ((getValue(nums[i]) == mid) && nums[i] < target));
do{
j–;
}while((getValue(nums[j]) > mid) || ((getValue(nums[j]) == mid) && nums[j] > target));
if(i < j){
int num = nums[i];
nums[i] = nums[j];
nums[j] = num;
}
}
quickSort(nums,left,j);
quickSort(nums,j + 1,right);
}
}
public static int getValue(int num){
int sum = 0;
if(num == 0){
return num;
}
while(num > 0){
sum += num % 10;
num /= 10;
}
return sum;
}
}