cho.sh
Notes
Loading...

K-th Digit in a Concatenated Number String

Time limit

2s

Memory limit

64 MB

Problem

Write all integers from 1 through N in order, without spaces, to form one long digit string.

1234567891011121314151617181920212223...

Find the digit that appears in the k-th position from the beginning of this string.

Input

The first line contains two integers N and k, separated by one or more spaces.

  • 1 ≤ N ≤ 100,000,000
  • 1 ≤ k ≤ 1,000,000,000

Output

If the concatenated string is shorter than k digits, print -1. Otherwise, print the digit at the k-th position from the beginning.