Олимпиадный тренинг

Задача 44311. Prestigious room


Задача

Темы:
In one very influential organization, in order to simplify the control of the entry of employees' vehicles into the territory, it was decided that the license plates of all employees should have the same product of digits equal to the number N.
Numbers in this country can be any natural numbers, and the inhabitants of the country are very fond of "small" numbers — the lower the number in the car number, the more prestigious it is considered.
The director of the organization wants none of the employees to have a more prestigious number than him. Since the organization is very influential, the director can get any number he wants.

Input
The program receives as input one natural number N, not exceeding 1018, — work
numbers of car numbers of employees of a very influential organization.
Please note that the value of N can exceed the value of a 32-bit integer variable, so you must use 64-bit integer data types (long long in C++, int64 in Pascal, long in Java and C#).< /strong>

Imprint
Print a single integer — the minimum value of the car number of the director of a very influential organization.
If no matching number exists, the program should output the number «−1».
Examples
# Input Output
1 70 257
2 101 -1