Problem: Janusz is a businessman. He owns a company "Januszex", which produces games for teenagers. Last hit of Januszex was a cool one-person game "Make it one". The player is given a sequence of n integers a_i.

It is allowed to select any subset of them, and the score is equal to the greatest common divisor of selected elements. The goal is to take as little elements as it is possible, getting the score 1. Now Janusz wonders, for given sequence, how much elements should the player choose?

Input

The first line contains an only integer n (1 ≤ n ≤ 300 000) — the number of integers in the sequence.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000).

Output

If there is no subset of the given sequence with gcd equal to 1, output -1.

Otherwise, output exactly one integer — the size of the smallest subset with gcd equal to 1.

Examples

Input

3
10 6 15


Output

3


Input

3
2 4 6


Output

-1


Input

7
30 60 21 42 70 15 30


Output

3

Note

In the first example, selecting a subset of all numbers gives a gcd of 1 and for all smaller subsets the gcd is greater than 1.

In the second example, for all subsets of numbers the gcd is at least 2. 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
template <typename T>
class IntegerIterator
    : public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> {
 public:
  explicit IntegerIterator(T value) : value(value) {}
  IntegerIterator& operator++() {
    ++value;
    return *this;
  }
  IntegerIterator operator++(int) {
    IntegerIterator copy = *this;
    ++value;
    return copy;
  }
  IntegerIterator& operator--() {
    --value;
    return *this;
  }
  IntegerIterator operator--(int) {
    IntegerIterator copy = *this;
    --value;
    return copy;
  }
  T operator*() const { return value; }
  bool operator==(IntegerIterator rhs) const { return value == rhs.value; }
  bool operator!=(IntegerIterator rhs) const { return !(*this == rhs); }

 private:
  T value;
};
template <typename T>
class IntegerRange {
 public:
  IntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }
  IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); }
  IntegerIterator<T> end() const { return IntegerIterator<T>(end_); }

 private:
  T begin_;
  T end_;
};
template <typename T>
class ReversedIntegerRange {
  using IteratorType = std::reverse_iterator<IntegerIterator<T>>;

 public:
  ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }
  IteratorType begin() const {
    return IteratorType(IntegerIterator<T>(begin_));
  }
  IteratorType end() const { return IteratorType(IntegerIterator<T>(end_)); }

 private:
  T begin_;
  T end_;
};
template <typename T>
IntegerRange<T> range(T to) {
  return IntegerRange<T>(0, to);
}
template <typename T>
IntegerRange<T> range(T from, T to) {
  return IntegerRange<T>(from, to);
}
template <typename T>
IntegerRange<T> inclusiveRange(T to) {
  return IntegerRange<T>(0, to + 1);
}
template <typename T>
IntegerRange<T> inclusiveRange(T from, T to) {
  return IntegerRange<T>(from, to + 1);
}
template <typename T>
ReversedIntegerRange<T> downrange(T from) {
  return ReversedIntegerRange<T>(from, 0);
}
template <typename T>
ReversedIntegerRange<T> downrange(T from, T to) {
  return ReversedIntegerRange<T>(from, to);
}
template <typename T>
ReversedIntegerRange<T> inclusiveDownrange(T from) {
  return ReversedIntegerRange<T>(from + 1, 0);
}
template <typename T>
ReversedIntegerRange<T> inclusiveDownrange(T from, T to) {
  return ReversedIntegerRange<T>(from + 1, to);
}
std::vector<int> linearSieve(int maxN) {
  ;
  std::vector<int> leastPrimes(maxN + 1);
  std::vector<int> primes;
  for (int i = 2; i <= maxN; ++i) {
    if (leastPrimes[i] == 0) {
      leastPrimes[i] = i;
      primes.push_back(i);
    }
    for (int prime : primes) {
      if (i * prime > maxN) {
        break;
      }
      leastPrimes[i * prime] = prime;
    }
  }
  return leastPrimes;
}
template <typename T>
T gcd(T a, T b) {
  while (b) {
    T tmp = a % b;
    a = b;
    b = tmp;
  }
  return a;
}
template <typename R>
void sort(R& range) {
  std::sort(range.begin(), range.end());
}
template <typename R, typename Comp>
void sort(R& range, Comp comp) {
  std::sort(range.begin(), range.end(), comp);
}
template <typename R>
void reverse(R& range) {
  std::reverse(range.begin(), range.end());
}
template <typename R, typename T>
auto lower_bound(const R& range, const T& value) -> decltype(range.begin()) {
  return std::lower_bound(range.begin(), range.end(), value);
}
template <typename R, typename T, typename Comp>
auto lower_bound(const R& range, const T& value, Comp comp)
    -> decltype(range.begin()) {
  return std::lower_bound(range.begin(), range.end(), value, comp);
}
template <typename R, typename T>
auto upper_bound(const R& range, const T& value) -> decltype(range.begin()) {
  return std::upper_bound(range.begin(), range.end(), value);
}
template <typename R, typename T, typename Comp>
auto upper_bound(const R& range, const T& value, Comp comp)
    -> decltype(range.begin()) {
  return std::upper_bound(range.begin(), range.end(), value, comp);
}
template <typename R>
auto min_element(const R& range) -> decltype(range.begin()) {
  return std::min_element(range.begin(), range.end());
}
template <typename R>
auto max_element(const R& range) -> decltype(range.begin()) {
  return std::max_element(range.begin(), range.end());
}
template <typename R>
bool next_permutation(R& range) {
  return std::next_permutation(range.begin(), range.end());
}
template <typename T>
void unique(std::vector<T>& range) {
  range.erase(std::unique(range.begin(), range.end()), range.end());
}
template <typename R>
R sorted(R range) {
  sort(range);
  return range;
}
template <typename R, typename Comp>
R sorted(R range, Comp comp) {
  sort(range, comp);
  return range;
}
template <typename R>
R reversed(R range) {
  reverse(range);
  return range;
}
using namespace std;
class TaskF {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    vector<int> a(n);
    int magic = 300000;
    auto lp = linearSieve(magic);
    int globalGcd = 0;
    for (int i : range(n)) {
      in >> a[i];
      auto& c = a[i];
      while (c != 1 && c % (lp[c] * lp[c]) == 0) {
        c /= lp[c];
      }
      globalGcd = gcd(globalGcd, a[i]);
    }
    if (globalGcd != 1) {
      out << -1;
      return;
      ;
    }
    sort(a);
    unique(a);
    vector<int64_t> cnt(magic);
    for (int x : a) {
      ++cnt[x];
    }
    vector<int64_t> cntsev = cnt;
    for (int i = 1;; ++i) {
      if (cntsev[1]) {
        out << i << "\n";
        return;
      }
      vector<int64_t> cntsum(magic);
      for (int x : downrange(magic, 1)) {
        for (int t = x; t < magic; t += x) {
          cntsum[x] += cnt[t];
        }
      }
      vector<int64_t> cntsevsum(magic);
      for (int x : downrange(magic, 1)) {
        for (int t = x; t < magic; t += x) {
          cntsevsum[x] += cntsev[t];
        }
      }
      vector<int64_t> cntnextsum(magic);
      for (int x : downrange(magic, 1)) {
        cntnextsum[x] = cntsevsum[x] * cntsum[x];
      }
      vector<int64_t> cntnext = cntnextsum;
      for (int x : downrange(magic, 1)) {
        for (int t = 2 * x; t < magic; t += x) {
          cntnext[x] -= cntnext[t];
        }
      }
      for (int x : downrange(magic, 1)) {
        if (cntnext[x] != 0) {
          cntnext[x] = 1;
        }
      }
      cntsev = cntnext;
    }
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  TaskF solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  in.tie(nullptr);
  out << std::fixed;
  out.precision(20);
  solver.solve(in, out);
  return 0;
}