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 num = s.to_big_i s = s.chars.map &.to_i n = s.size if s.count(s[0]) == n puts s.join exit end g = 0 s.each { |i| s.each { |j| g = g.gcd(9*(i - j)) if i > j } } p num.gcd(g)