ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

1233. Amusing Numbers

Time limit: 1.0 second
Memory limit: 64 MB
Let us consider the set of integer numbers between 1 and N inclusive. Let us order them lexicographically (i. e. like in the vocabulary), for example, for N = 11 the order would be: 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9.
Let us denote the position of the number K in this ordering as QN,K. For example, Q11,2 = 4. Given numbers K and M find the smallest N such that QN,K = M.

Input

Input contains two integer numbers K and M (1 ≤ K, M ≤ 109) separated by a space.

Output

If such N that QN,K = M exists then write the smallest such N, otherwise write 0.

Samples

inputoutput
2 4
11
2 1
0
100000001 1000000000
100000000888888879
1000000000 11
0
Problem Author: Andrew Stankevich
Problem Source: 2002-2003 ACM Northeastern European Regional Programming Contest