Problem1036--A number in a sequence

1036: A number in a sequence

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

Given a positive integer N (3<= N <= 15), we would like to create 
an increasing sequence using the numbers of $N^x$ ( x is integers and 0 <= x),
each term in the sequence can be a number of $N^x$ or the sum of some numbers
of $N^x$. For example, when N = 3, the sequence is :
1 3 4 9 10 12 13 ...
Here is some examples for the first few terms:
1 is $3^0$
3 is $3^1$
4 is the sum of $3^0 + 3^1$
In this problem, given a number M , please output the Mth term of the sequence.

Input

There are two integers N and M in a line.  ( $ 0 \leq N \leq 15 $ ) ( $ 10 \leq M \leq 1000 $)

Output

One integer which is the Mth term of the sequence. The output is guaranteed smaller than $2^{62}$

Sample Input Copy

3 100

Sample Output Copy

981

Source/Category

NOIP