import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

void main() {
    int N = readln.chomp.to!int;
    auto A = readln.chomp.split(" ").map!(to!int).array;

    int ans = -1;
    void f(int a, int b) {
        int x = a * b;
        string s = x.to!string;
        int t = -1;
        foreach (c_; s) {
            int c = cast(int)(c_ - '0');
            if (t >= 0 && c - t != 1) return;
            t = c;
        }
        ans = max(ans, x);
    }

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int a = A[i], b = A[j];
            f(a, b);
        }
    }
    writeln(ans);
}