class Integer
    def seq?(i = nil)
        i ||= self % 10
        return false if self % 10 != i
        return true if self < 10
        (self / 10).seq?(i - 1)
    end
end
gets
a = gets.split.map(&:to_i)
p a.combination(2).map {|x, y| x * y}.select(&:seq?).max || -1
