#include using namespace std; int __gcd(int a, int b){ if (a > b){ swap(a, b); } while (a){ swap(a, b); a %= b; } return b; } string s; set S; int main(){ cin >> s; int sum = 0; bool f = true; for (int i = 0; i < s.size(); i++){ S.insert(s[i] - '0'); sum += (s[i] - '0'); if ((s[i] - '0') % 2){ f = false; } } if (S.size() == 1){ cout << s << endl; return 0; } int gc = 0; for (auto it = S.begin(); it != S.end(); it++){ for (auto itt = S.begin(); itt != S.end(); itt++){ int sa = abs(10 * (*it) + (*itt) - (10 * (*itt) + (*it))); gc = __gcd(gc, sa); } } if (gc % 9 == 0 && sum % 9){ gc /= 9; } if (gc % 3 == 0 && sum % 3){ gc /= 3; } while (f==false&&gc % 2 == 0){ gc /= 2; } cout << gc << endl; return 0; }