#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if(y < x) x = y; } template static void amax(T &x, U y) { if(x < y) x = y; } templateT gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); } int main() { char S[10002]; while(~scanf("%s", S)) { int len = (int)strlen(S); int cnt[10] = {}; for(const char *p = S; *p; ++ p) ++ cnt[*p - '0']; if(count(cnt, cnt + 10, 0) >= 9) { puts(S); continue; } assert(len >= 2); int diffcf = 0; rep(i, 10) if(cnt[i] != 0) reu(j, i + 1, 10) if(cnt[j] != 0) diffcf = gcd(diffcf, j - i); diffcf *= 9; int moddiff = 0; for(const char *p = S; *p; ++ p) (moddiff = moddiff * 10 + (*p - '0')) %= diffcf; int ans = gcd(diffcf, moddiff); printf("%d\n", ans); } return 0; }