#include #include #include #include using namespace std; typedef long long ll; ll gcd(ll a, ll b) { while (a) { b %= a; swap(a, b); } return b; } bool X[10]; bool Y[10]; int main() { for (int i = 1; i < 14; i++)Y[i] = true; string s; cin >> s; vector e(s.size()); for (int i = 0; i < s.size(); i++) { e[i] = s[i] - '0'; } int sum = 0; for (int i = 0; i < e.size(); i++) { if (e[i] % 2)Y[2] = false; X[e[i]] = true; sum += e[i]; } int cnt = 0; for (int i = 0; i < 10; i++) { if (X[i])cnt++; } if (cnt == 1) { cout << s << endl; return 0; } if (sum % 3)Y[3] = false; if (sum % 9)Y[9] = false; if (!Y[2]) { Y[4] = false; Y[6] = false; Y[8] = false; } else { if (X[2] || X[6]) Y[4] = false; if (!Y[3]) Y[6] = false; } Y[5] = false; Y[7] = false; Y[8] = false; int ans = 1; for (int i = 9; i > 0; i--) { if (Y[i]) { int a = gcd(ans,i); ans *= i; ans /= a; } } cout << ans << endl; return 0; }