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 g = s.chars.map(&.to_i).uniq.combinations(2).map { |(i, j)| 9 * (i - j).abs }.reduce(0) { |acc, x| acc.gcd(x) } if g == 0 puts s else puts s.to_big_i.gcd(g) end