#include using namespace std; #define endl '\n' typedef long long ll; string n; bool vis[20]; inline bool is_divisible(string x, ll mod) { ll remainder = 0; for (auto ch : n) remainder = (remainder * 10 + (ch - '0')) % mod; return !remainder; } int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> n; for (auto ch : n) vis[ch - '0'] = 1; ll gcd = 0; for (ll i = 0; i <= 9; i++) for (ll j = 0; j < i; j++) if (vis[i] && vis[j]) gcd = __gcd(gcd, 9 * (i - j)); if (!gcd) { cout << n << endl; return 0; } for (ll i = gcd; i >= 0; i--) if (gcd % i == 0 && is_divisible(n, i)) { cout << i << endl; break; } return 0; }