By using each of the digits from the set, , exactly once, and making use of the four arithmetic operations and brackets/parentheses, it is possible to form different positive integer targets.
Note that concatenations of the digits, like , are not allowed.
Using the set, , it is possible to obtain thirty-one different target numbers of which 36 is the maximum, and each of the numbers to can be obtained before encountering the first non-expressible number.
Given a set of distinct digits, , find the largest possible integer such that each integer from to is expressible using elements of and following the above rules. If is also not expressible, output instead.
The first line contains .
The second line contains space separated integers, the elements of .
Output a single integer, the answer to the problem.