lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end require "big" s = read_line a = s.chars.map(&.to_i).sort n = a.size g = 0 (0...n).each { |i| (i + 1...n).each { |j| g = g.gcd(9*(a[j] - a[i])) if a[j] != a[i] } } if g == 0 puts s else puts s.to_big_i.gcd(g) end