#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define ri register int #define rl register long long #define mst(x,y) memset(x, y, sizeof(x)) #define ciallo putchar('\n') #define ilv inline void #define ili inline int #define ilb inline bool #define ill inline long long constexpr auto N = 1000010; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } string str; vector b; bool check(ll x) { ll temp = 0; for (auto i : str) temp = (temp * 10 + i - '0') % x; return temp; } int main() { /*freopen("gcd.in", "r", stdin); freopen("gcd.out", "w", stdout);*/ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> str; set temp(str.begin(), str.end()); if (temp.size() == 1) { cout << str; return 0; } ll t = 0; for (auto i : str) for (auto j : str) if (i < j) t = gcd(t, 9ll * (j - i)); for (rl i = 1; i * i <= t; ++i) { if (!(t % i)) { b.push_back(i); if (i != t / i) b.push_back(t / i); } } sort(b.rbegin(), b.rend()); for (auto i : b) { if (!check(i)) { cout << i; return 0; } } /*fclose(stdin); fclose(stdout);*/ return 0; }