#include using namespace std; typedef __int128 Int; int f(string t){ sort(t.begin(),t.end()); long long w = -1; do{ long long x = atoi(t.c_str()); if( w == -1 ) w = x; w = __gcd(x,w); }while(next_permutation(t.begin(),t.end())); return w; } bool single(string s){ return s.size() == count(s.begin(),s.end(),s[0]); } int main(){ string s; cin >> s; if( single(s) ){ cout << s << endl; return 0; } if( s.size() <= 6 ){ cout << f(s) << endl; return 0; } int sum = 0; for(auto &c : s ) sum += c - '0'; int ev = 1; for(int i = 8 ; i >= 2 ; i-=2){ int f = 1; for(int j = 0 ; j < s.size() ; j++) if( (s[j] - '0') % i != 0 ){ f = 0; } if(f){ ev = i; break; } } int od = sum % 9 == 0 ? 9 : sum % 3 == 0 ? 3 : 1; cout << od * ev << endl; }