https://www.acmicpc.net/problem/1790
import java.util.Scanner;
public class Main {
static long count(long t){
long num=1;
for(int i=0;i<t;i++){
num*=10;
}
return num;
}
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int k=s.nextInt();
int t=1;
long num=0;
int r=0;
int e=0;
while(true){
long max=(count(t)-count(t-1))*t;
if(num+max>=k){
k-=num;
r=k/t;
e=k%t;
n-=r;
break;
}
num+=max;
n-=count(t)-count(t-1);
t++;
}
r+=count(t-1)-1;
if(n<0 || n==0 && e!=0) System.out.print("-1");
else if(e==0){
String m=r+"";
System.out.format("%c",m.charAt(m.length()-1));
}
else{
r+=1;
String m=r+"";
System.out.format("%c",m.charAt(e-1));
}
}
}