#include using namespace std; bool check(const string &s, int m) { int r = 0; for (char c: s) { r = 10 * r + (c - '0'); r %= m; } return r == 0; } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a%b); } string solve(const string &s) { vector v; for (char c: s) v.push_back(c - '0'); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); if (v.size() == 1) return s; long long g = 0; for (int a: v) for (int b: v) g = gcd(g, 9 * abs(a - b)); for (int x = g; x > 1; x--) { if (g % x == 0 && check(s, x)) return to_string(x); } return "1"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; cout << solve(s) << endl; return 0; }