eolymp
bolt
Try our new interface for solving problems
Problems

Lucky ticket 2

Lucky ticket 2

We call a sequence of numbers tickets of length n. A ticket is a happy, if there exists a number (1kn) such that prb2619. The number k is called the boundary with happiness.

Your task - to write a program that determines for a given a ticket to the lowest limit of happiness, if it exists.

Input

The first line contains the number n (2 ≤ n ≤ 106) - the length of a ticket A. In the second row contain numbers a[1], a[2], ..., a[n] (0a[i]9), separated by spaces.

Output

If a ticket is a happy, remove it lowest limit of happiness, otherwise output "-1".

Time limit 1 second
Memory limit 64 MiB
Input example #1
4
3 2 1 6
Output example #1
3
Author Vladimir Ulyantsev