beecrowd | 1226

Space Elevator

Maratona de Programação da SBC Brazil

Timelimit: 2

China is building a space elevator, which will allow the launching probes and satellites to a much lower cost, enabling not only scientific research projects but also space tourism.

However, the Chinese are very superstitious, and therefore have a very especial care with the numbering of floors in the elevator: they do not use any number containing the digit “4” or the sequence of digits “13”. Thus, they do not use the fourth floor or the floor 13 or the floor 134 nor the floor 113, but use the floor 103. Thus, the first floors are numbered 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, . . .

As the space elevator has many levels, and levels must be numbered, the Chinese asked you to write a program that, given the level, indicates which number should be assigned to it.

Input

The input contains several test cases. Each test case consists of a single line containing an integer N (1 ≤ N ≤ 1018) which indicates the floor whose number should be determined.

Output

For each test case, print a line containing a single integer indicating the number assigned to the N-th floor.

Sample Input Sample Output

1
4
11
12
440

1
5
12
15
666