#include #define rep(i,n) for(int i=0;i<(int)n;i++) #define all(c) (c).begin(),(c).end() #define mp make_pair #define pb push_back #define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++) #define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)< vi; typedef pair pi; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; string in; int main(){ cin >> in; int ans = 0; vi v; bool allsame = 1; set s, t; for(char c : in){ if(c != in[0]) allsame = 0; s.insert(c - '0'); } if(allsame){ cout << in << endl; return 0; } for(int a : s) for(int b : s) if(a > b) v.pb(9 * (a - b)); for(int x : v) for(int y = x, i = 1; i * i <= y; i++) if(y % i == 0){ t.insert(i); t.insert(y / i); } for(int x : t){ int d = 0; for(char c : in){ d *= 10; d += c - '0'; d %= x; } if(d == 0) ans = max(ans, x); } cout << ans << endl; return 0; }