#include #include using namespace std; long long factorial(long long x){ if(x == 0){ return 1; } long long result = 1; for (int i = 1; i <= x; ++i) { result *= i; } return result; } long long f(long long x){ if(x >= 0 and x <= 9){ return factorial(x); }else{ return factorial(x % 10) + f(int (x / 10)); } } int main() { int y; cin >> y; long long x = 0, res; for (int i = 0; i < 1000000000; ++i) { x = i; res = f(x); if(res == y){ cout << x; return 0; } } return 0; }