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 n = s.size if s.count(s[0]) == n puts s exit end p (0...n).to_a.combinations(2).map { |(i, j)| ("#{s[i]}#{s[j]}".to_i - "#{s[j]}#{s[i]}".to_i).abs }.reduce(0) { |i, j| i.gcd(j) }.gcd(s.to_i)