#include #include #include #include using namespace std; string s; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> s; bool same = true; for (int i = 1; i < s.size(); i++) { if (i >= 1 && s[i] != s[i - 1]) same = false; } if (same) cout << s << '\n'; else { int ret = 64 * 81 * 25 * 49; int bit = 0, cur = 0; for (int i = 0; i < s.size(); i++) { bit |= 1 << (s[i] - '0'); cur = (cur * 10 + (s[i] - '0')) % ret; } ret = gcd(ret, cur); for (int i = 0; i < 10; i++) { for (int j = i + 1; j < 10; j++) { if (((bit >> i) & 1) && ((bit >> j) & 1)) { ret = gcd(ret, (j - i) * 9); } } } cout << ret << endl; } return 0; }