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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
void printVector(vector<int> &v) {
  for (auto x : v) cout << x << " ";
  cout << "\n";
}
void SieveOfEratosthenes(vector<int> &v) {
  int n = 1000;
  vector<int> prime(n + 1, 1);
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == 1) {
      for (int i = p * p; i <= n; i += p) prime[i] = 0;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p]) v.push_back(p);
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    vector<int> pr;
    SieveOfEratosthenes(pr);
    set<pair<int, int> > adjlist;
    int ans = INT_MAX;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      int sq = sqrt(a[i]);
      if (a[i] == sq * sq) {
        ans = 1;
      }
    }
    if (ans == 1) {
      cout << 1 << "\n";
      return 0;
    }
    for (int i = 0; i < n; i++) {
      int m = a[i];
      int found = 0;
      for (auto x : pr) {
        if (m % x == 0) {
          found = 1;
          int c = 0;
          while (m % x == 0) {
            c++;
            m /= x;
          }
          if (c % 2 == 0) {
            if (m > 1) {
              if (adjlist.find({1, m}) == adjlist.end())
                adjlist.insert({1, m});
              else
                ans = 2;
            } else
              cout << "error\n";
          } else {
            if (m > 1) {
              int sq = sqrt(m);
              if (sq * sq == m) {
                if (adjlist.find({1, x}) == adjlist.end())
                  adjlist.insert({1, x});
                else
                  ans = 2;
              } else {
                if (adjlist.find({x, m}) == adjlist.end())
                  adjlist.insert({x, m});
                else
                  ans = 2;
              }
            } else {
              if (adjlist.find({1, x}) == adjlist.end())
                adjlist.insert({1, x});
              else
                ans = 2;
            }
          }
          break;
        }
      }
      if (found == 0) {
        if (adjlist.find({1, a[i]}) == adjlist.end())
          adjlist.insert({1, a[i]});
        else
          ans = 2;
      }
      if (ans == 2) {
        cout << 2 << "\n";
        return 0;
      }
    }
    vector<int> prime;
    map<int, int> mp;
    int sz = 0;
    for (auto x : adjlist) {
      int f = x.first;
      int s = x.second;
      if (mp.find(f) == mp.end()) {
        mp.insert({f, sz});
        sz++;
        prime.push_back(f);
      }
      if (mp.find(s) == mp.end()) {
        mp.insert({s, sz});
        sz++;
        prime.push_back(s);
      }
    }
    vector<vector<int> > edges(sz);
    for (auto x : adjlist) {
      int f = x.first;
      int s = x.second;
      edges[mp[f]].push_back(mp[s]);
      edges[mp[s]].push_back(mp[f]);
    }
    if (ans > 1) {
      for (int i = 0; i < sz; i++) {
        if (prime[i] > 1000) continue;
        vector<int> visited(sz, 0);
        vector<int> dis(sz, 0);
        vector<int> parent(sz);
        int root = i;
        parent[root] = -1;
        visited[root] = 1;
        queue<int> q;
        q.push(root);
        while (!q.empty()) {
          int u = q.front();
          for (auto x : edges[u]) {
            if (visited[x] == 0) {
              visited[x] = 1;
              q.push(x);
              dis[x] = dis[u] + 1;
              parent[x] = u;
            } else {
              if (parent[x] != u && parent[u] != x)
                ans = min(ans, dis[x] + dis[u] + 1);
            }
          }
          q.pop();
        }
      }
    }
    if (ans == INT_MAX)
      cout << -1 << "\n";
    else
      cout << ans << "\n";
  }
}