#include #include "bits/stdc++.h" #include using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { std::string N; std::cin >> N; std::unordered_set S; for (char c : N) { S.insert(c - '0'); } if (S.size() == 1) { std::cout << N << std::endl; } else { int G = 0; for (int y : S) { for (int x : S) { if (y > x) { G = __gcd(G, 9 * (y - x)); } } } std::cout << __gcd(stoi(N), G) << std::endl; } return 0; }