#include <iostream> #include <vector> #include <algorithm> #include <map> #include <queue> #include <cstdio> #include <ctime> #include <assert.h> #include <chrono> #include <random> #include <numeric> #include <set> using namespace std; typedef long long int ll; using ull = unsigned long long; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); string s,t; cin >> s; t=s; sort(t.begin(), t.end()); if(t[0]==t.back()){ cout << t << endl; } else{ int n=s.size(); int g=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ g=__gcd(g,abs((s[i]-'0')-(s[j]-'0'))); } } g*=9; int d=0; for(char c:t){ d=(d*10+(c-'0'))%g; } printf("%d\n",__gcd(g,d)); } }