# include using namespace std; typedef long long ll; # define int long long # define lc u << 1 # define rc u << 1 | 1 # define fi first # define se second const int N = 15; string n; bool hav[N]; signed main () { // freopen ("gcd.in", "r", stdin); freopen ("gcd.out", "w", stdout); cin >> n; for (auto c : n) hav[c - '0'] = 1; int g = 0; for (int i = 0; i <= 9; i ++ ) { for (int j = 0; j < i; j ++ ) { if (hav[i] && hav[j]) g = __gcd (g, 9 * (i - j)); } } if (!g) return cout << n << "\n", 0; for (int i = g; i >= 0; i -- ) { if (g % i == 0) { int t = 0; for (auto c : n) t = (t * 10 % i + (c - '0')) % i; if (!t) return printf ("%lld\n", i), 0; } } return 0; }