Reading Croatian Numbers

Time limit1sMemory limit128 MB

Problem

The table below summarizes the first word used when reading positive integers in Croatian. Numbers are read in groups of three digits from the right. If the leading digit of the highest place is not 1, the reading begins with that digit's word. If it is 1, that 1 is usually omitted and the word for the place value is read first. The exceptions are the number 1 itself, which is read as jedan, and numbers whose highest three-digit group is from 11 to 19, which begin with the corresponding word in the table. For example, 40 begins with četiri, 705 with sedam, 150 with sto, 1 500 with tisuću, and 15 000 with petnaest.

1jedan10deset1xxsto
2dva11jedanaest1xxxtisuću
3tri12dvanaest1xxxxdeset tisuća
4četiri13trinaest1xxxxxsto tisuća
5pet14četrnaest1xxxxxxmilijun
6šest15petnaest1xxxxxxxdeset milijuna
7sedam16šesnaest1xxxxxxxxsto milijuna
8osam17sedamnaest1xxxxxxxxxmilijarda
9devet18osamnaest1xxxxxxxxxxdeset milijardi
19devetnaest1xxxxxxxxxxxsto milijardi

For a given uppercase letter, list all positive integers whose Croatian reading starts with that letter in increasing order. For example, the sequence for P starts 5, 15, 50, 51, 52, ..., 59, 500, 501, ...

Find the N-th number in the sequence for the given letter.

Input

The input contains a letter L and an integer N separated by a space. L is one of D, J, M, O, P, S, and T.

The answer is guaranteed not to exceed 10^12.

Output

Print the N-th number in the sequence.