#T363. Blah数集

Blah数集

Description

The great mathematician Gauss discovered an interesting set of natural numbers called Blah during his childhood. For a base a, the set Ba is defined as follows:

  1. a is the base of the set Ba and is the first element of Ba.
  2. If x is in the set Ba, then 2x + 1 and 3x + 1 are also in Ba.
  3. No other elements are in Ba.

Now, little Gauss wants to know: if the elements of Ba are arranged in ascending order, what is the value of the N-th element?

Input Format

The input consists of multiple lines. Each line contains two numbers: the base a (1 ≤ a ≤ 50) of the set and the desired element index n (1 ≤ n ≤ 1,000,000).

Output Format

For each input, output the value of the n-th element in the set Ba.

1 100
28 5437


418
900585