
import java.util.*;
public static Integer get(int count,int c){if(count<3||count>7){return -1;}int[] arr =new int[count];List<Integer> res = new ArrayList<>();for(int i=(int) Math.pow(10,count-1);i<(int) Math.pow(10,count);i++){getArr( i,arr);int sum = 0;for(int j = 0;j<arr.length;j++){sum+= Math.pow(arr[j],arr.length);}if(sum == i){res.add(i);}}if(res.size()<c){return res.get(res.size()-1)*c;}return res.get(c);
}public static int[] getArr(int i,int[] arr){int count = 0,j=arr.length;while(count<arr.length){arr[count] = i/ ((int) Math.pow(10,j-1));i = i- arr[count]* ((int) Math.pow(10,j-1));j--;count++;}return arr;
}public static void main(String[] args) {Scanner in = new Scanner(System.in);while (in.hasNextLine()) { int count = in.nextInt();int c = in.nextInt();System.out.println(get(count, c));}
}