#P17188. [ICPC 2017 Hong Kong R] Sets

[ICPC 2017 Hong Kong R] Sets

Problem Description

For a fixed number nn, we define S1S_1 as the set of integers 1,2,,n1, 2, \dots, n. And for any i>1i > 1, we define SiS_i as a set containing all sums of two different numbers in Si1S_{i-1}.

For example, if n=3n = 3, we have

$$\begin{matrix} S_1 & = &\{1,2,3\},\\ S_2 & = &\{3,4,5\},\\ S_3 & = &\{7,8,9\},\\ S_4 & = &\{15, 16, 17\}.\\ \end{matrix}$$

Then, we sort each set respectively, and combine them in order into a sequence LL. In the above case, we have the sequence L=1,2,3,3,4,5,7,8,9,15,16,17,L = 1, 2, 3, 3, 4, 5, 7, 8, 9, 15, 16, 17, \dots.

Now, given integers nn and kk, what is the kk-th number in sequence LL?

Input Format

The input file contains several test cases, please handle it to the end of file.

For each case, there is only one line containing two integers nn and kk (n1000,k101000n \le 1000, k \le 10^{1000}). When n=3n = 3, the input satisfies that k100000k \leq 100000.

Output Format

For each case, output one integer indicating the kk-th number of the sequence. Output 1-1 if it does not exist.

4 6
2 20
4
-1