n = int(eval(input()))

a = list(map(int, input().split()))



ma = -1

for i in range(n - 1):

    for j in range(i + 1, n):

        pro = a[i] * a[j]



        digit = [pro % (10 ** k) // (10 ** (k - 1)) for k in range(1, 10)]



        while digit[-1] == 0:

            digit = digit[:-1]



        if len(digit) == 1:

            ma = max(ma, pro)

            continue



        flag = True

        for k in range(len(digit) - 1):

            if digit[k + 1] - digit[k] != -1:

                flag = False

                break



        if flag:

            ma = max(ma, pro)



print(ma)

n = int(eval(input()))

a = list(map(int, input().split()))



ma = -1

for i in range(n - 1):

    for j in range(i + 1, n):

        pro = a[i] * a[j]

        

        pre = pro % 10

        pro //= 10



        while pro:

            if pre - pro % 10 == 1:

                pre = pro % 10

                pro //= 10

            else:

                break



        if not pro:

            ma = max(ma, a[i] * a[j])

print(ma)

n = int(eval(input()))
a = list(map(int, input().split()))
ma = -1
for i in range(n - 1):
    for j in range(i + 1, n):
        pro = a[i] * a[j]
        digit = [pro % (10**k) // (10 ** (k - 1)) for k in range(1, 10)]
        while digit[-1] == 0:
            digit = digit[:-1]
        if len(digit) == 1:
            ma = max(ma, pro)
            continue
        flag = True
        for k in range(len(digit) - 1):
            if digit[k + 1] - digit[k] != -1:
                flag = False
                break
        if flag:
            ma = max(ma, pro)
print(ma)

n = int(eval(input()))
a = list(map(int, input().split()))
ma = -1
for i in range(n - 1):
    for j in range(i + 1, n):
        pro = a[i] * a[j]
        pre = pro % 10
        pro //= 10
        while pro:
            if pre - pro % 10 == 1:
                pre = pro % 10
                pro //= 10
            else:
                break
        if not pro:
            ma = max(ma, a[i] * a[j])
print(ma)

-        digit = [pro % (10**k) // (10 ** (k - 1)) for k in range(1, 10)] -        while digit[-1] == 0: -            digit = digit[:-1] -        if len(digit) == 1: -            ma = max(ma, pro) -            continue -        flag = True -        for k in range(len(digit) - 1): -            if digit[k + 1] - digit[k] != -1: -                flag = False +        pre = pro % 10 +        pro //= 10 +        while pro: +            if pre - pro % 10 == 1: +                pre = pro % 10 +                pro //= 10 +            else: -        if flag: -            ma = max(ma, pro) +        if not pro: +            ma = max(ma, a[i] * a[j])