#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a, b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define show(x) cout <<#x<<" = "<<(x)<P; const int MAX_N = 100005; int gcd(int a,int b) { if(a % b == 0){ return b; }else{ return gcd(b,a%b); } } int main() { string s; cin >> s; vector vec((int)s.size()); bool flag = true; rep(i,s.size()){ vec[i] = (int)(s[i] - '0'); if(i >= 1 && vec[i] != vec[i-1]){ flag = false; } } if(flag){ cout << s << endl; return 0; } int sm = accumulate(all(vec),0); int g=1; rep(i,9){ g *= i+1; } rep(i,vec.size()){ g = gcd(g,vec[i]); } if(sm % 9 == 0){ cout << g * 9 / gcd(g,9) << endl; }else if(sm % 3 == 0){ cout << g * 3 / gcd(g,3) << endl; }else{ cout << g << endl; } return 0; }