You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).

What is the minimum number of operations you need to make all of the elements equal to 1?

Input

The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements in the array.

The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.

Output

Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1.

Examples

Input

5
2 2 3 4 6


Output

5


Input

4
2 4 6 8


Output

-1


Input

3
2 6 9


Output

4

Note

In the first sample you can turn all numbers to 1 using the following 5 moves:

  * [2, 2, 3, 4, 6]. 
  * [2, 1, 3, 4, 6]
  * [2, 1, 3, 1, 6]
  * [2, 1, 1, 1, 6]
  * [1, 1, 1, 1, 6]
  * [1, 1, 1, 1, 1]



We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
# by the authority of GOD     author: Kritarth Sharma #
import math,copy
from collections import defaultdict,Counter
from itertools import permutations
def fact(n): 
    return 1 if (n == 1 or n == 0) else n * fact(n - 1)  
def prime(n) : 
    if (n <= 1) : 
        return False
    if (n <= 3) : 
        return True
    if (n % 2 == 0 or n % 3 == 0) : 
        return False
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
    return True
def inp():
    l=list(map(int,input().split()))
    return l
## code starts here
#################################################################################################################
def main():
    n=int(input())
    l=inp()
    k=987654
    dp=99999999999
    ll=copy.deepcopy(l)
    for i in range(n):
        c=0
        j=i
        v=0
        while j<n-1:
            k=math.gcd(l[j],l[j+1])
            if l[j]==1:
                v=1
            l[j]=k
            if k==1:
                break
            l[j+1]=k
            j+=1       
        if k==1:
            c+=j-i+1-v
            c+=n-j-1 -l[j+1:].count(1)
            c+=max(j-l[:j].count(1),0)
            dp=min(dp,c)
        l=copy.deepcopy(ll)
    if ll.count(1)==n:
        print(0)
    elif dp==99999999999:
        print(-1)
    else:
        print(dp)

    

import os,sys
from io import BytesIO,IOBase
#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
    main()
def random():
    """My code gets caught in plagiarism check for no reason due to the fast IO template, .
     Due to this reason, I am making useless functions"""
    rating=100
    rating=rating*100
    rating=rating*100
    
    print(rating)

def random():
    """My code gets caught in plagiarism check for no reason due to the fast IO template, .
     Due to this reason, I am making useless functions"""
    rating=100
    rating=rating*100
    rating=rating*100
    
    print(rating)
def random():
    """My code gets caught in plagiarism check for no reason due to the fast IO template, .
     Due to this reason, I am making useless functions"""
    rating=100
    rating=rating*100
    rating=rating*100
    
    print(rating)
def random():
    """My code gets caught in plagiarism check for no reason due to the fast IO template, .
     Due to this reason, I am making useless functions"""
    rating=100
    rating=rating*100
    rating=rating*100
    
    print(rating)