Problem: You are given an array a of length n that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.

A sequence a is a subsequence of an array b if a can be obtained from b by deletion of several (possibly, zero or all) elements.

Input

The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of a.

The second line contains n integers a_1, a_2, …, a_{n} (1 ≤ a_i ≤ 10^6) — the elements of the array a.

Output

Output the length of the shortest non-empty subsequence of a product of whose elements is a perfect square. If there are several shortest subsequences, you can find any of them. If there's no such subsequence, print "-1".

Examples

Input


3
1 4 6


Output


1

Input


4
2 3 6 6


Output


2

Input


3
6 15 10


Output


3

Input


4
2 3 5 7


Output


-1

Note

In the first sample, you can choose a subsequence [1].

In the second sample, you can choose a subsequence [6, 6].

In the third sample, you can choose a subsequence [6, 15, 10].

In the fourth sample, there is no such subsequence.

Solution (in PYTHON3):

Solution:
import sys
input = sys.stdin.readline

n=int(input())
A=list(map(int,input().split()))

Primes=(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997)

E=[[] for i in range(10**6)]
U=set()

for i in range(n):
    a=A[i]
    X=[]
    for p in Primes:
        while a%(p*p)==0:
            a//=p*p
        if a%p==0:
            a//=p
            X.append(p)
    if a!=1:
        X.append(a)

    if a==1 and X==[]:
        print(1)
        sys.exit()
    elif len(X)==1:
        E[1].append(X[0])
        E[X[0]].append(1)

        U.add(X[0])
    else:
        E[X[0]].append(X[1])
        E[X[1]].append(X[0])

        U.add(X[0]*X[1])

if len(A)!=len(U):
    ANS=2
else:
    ANS=n+5

D=[]
E2=[]
for i in range(10**6):
    if E[i]==[]:
        continue
    D.append(i)
    E2.append(E[i])

DD={x:i for i,x in enumerate(D)}
for i in range(len(E2)):
    for k in range(len(E2[i])):
        E2[i][k]=DD[E2[i][k]]

from collections import deque

for start in range(min(170,len(E2))):
    if E2[start]==[]:
        continue
    Q=deque([start])
    D=[0]*len(E2)
    FROM=[0]*len(E2)
    D[start]=1

    while Q:
        x=Q.popleft()
        if D[x]*2-2>=ANS:
            break
        for to in E2[x]:
            if to==FROM[x]:
                continue
            elif D[to]==0:
                Q.append(to)
                FROM[to]=x
                D[to]=D[x]+1
            else:
                #print(start,x,to,D[x],D[to])
                ANS=min(ANS,D[x]+D[to]-1)

if ANS>len(A):
    print(-1)
else:
    print(ANS)