#include using namespace std; string s; map S; int main(){ cin >> s; for (int i = 0; i < s.size(); i++){ S[s[i] - '0']++; } if (S.size() == 1){ cout << s << endl; return 0; } int gc = 0; for (auto it = S.begin(); it != S.end(); it++){ S[(*it).first]--; for (auto itt = S.begin(); itt != S.end(); itt++){ if ((*itt).second){ int a = 10 * (*it).first; a += (*itt).first; int b = 10 * (*itt).first; b += (*it).first; int sa = abs(a-b); if(sa)gc = __gcd(gc, sa); } } S[(*it).first]++; } cout << gc << endl; return 0; }