Package for this problem was not updated by the problem writer or Codeforces administration after we’ve upgraded the judging servers. To adjust the time limit constraint, solution execution time will be multiplied by 2. For example, if your solution works for 400 ms on judging servers, then value 800 ms will be displayed and used to determine the verdict.

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

E. Greedy Change

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputBilly investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amount of *n* coins of different face values, and the coins of each value are not limited in number. The task is to collect the sum *x* with the minimum amount of coins. Greedy algorithm with each its step takes the coin of the highest face value, not exceeding *x*. Obviously, if among the coins' face values exists the face value 1, any sum *x* can be collected with the help of greedy algorithm. However, greedy algorithm does not always give the optimal representation of the sum, i.e. the representation with the minimum amount of coins. For example, if there are face values {1, 3, 4} and it is asked to collect the sum 6, greedy algorithm will represent the sum as 4 + 1 + 1, while the optimal representation is 3 + 3, containing one coin less. By the given set of face values find out if there exist such a sum *x* that greedy algorithm will collect in a non-optimal way. If such a sum exists, find out the smallest of these sums.

Input

The first line contains an integer *n* (1 ≤ *n* ≤ 400) — the amount of the coins' face values. The second line contains *n* integers *a*_{i} (1 ≤ *a*_{i} ≤ 10^{9}), describing the face values. It is guaranteed that *a*_{1} > *a*_{2} > ... > *a*_{n} and *a*_{n} = 1.

Output

If greedy algorithm collects any sum in an optimal way, output -1. Otherwise output the smallest sum that greedy algorithm collects in a non-optimal way.

Examples

Input

5

25 10 5 2 1

Output

-1

Input

3

4 3 1

Output

6

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/20/2018 06:57:21 (d1).

Desktop version, switch to mobile version.

User lists

Name |
---|