Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
Language:
I know the k-th integer
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 2964Accepted: 648

Description

Sort the first n integers 1,2,3,...,n-1,n in lexicographical order, and the k-th integer is known as m. Can you tell me the smallest n?

For example,when n=11, the order is 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9. And the 4-th integer is 2.

Input

The input contains many test cases ended with EOF. Each test case contains only one line of two integers, k and m.

1 ≤ k, m ≤ 10^9

Output

For each test case output the smallest n in a single line. If there is no such n, just output 0.

Sample Input

4 2
2 1
1000 25

Sample Output

11
0
1831

Source

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator