import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.numeric; // gcd, fft void main() { auto n = readln.chomp.to!int, m = n; int[] a; while (m > 1) { a ~= m % 10; m /= 10; } a = a.sort().uniq.array; auto na = a.length; if (na == 1) { writeln(n); return; } auto ans = n; foreach (i; 0..na-1) foreach (j; i+1..na) ans = gcd(ans, 9*(a[j]-a[i])); writeln(ans); }