Problem: We call an array b_1, b_2, …, b_m good, if there exist two indices i < j such that b_i ⋅ b_j is a [perfect square](https://en.wikipedia.org/wiki/Square_number).

Given an array b_1, b_2, …, b_m, in one action you can perform one of the following: 

  * multiply any element b_i by any prime p; 
  * divide any element b_i by prime p, if b_i is divisible by p. 



Let f(b_1, b_2, …, b_m) be the minimum number of actions needed to make the array b good.

You are given an array of n integers a_1, a_2, …, a_n and q queries of the form l_i, r_i. For each query output f(a_{l_i}, a_{l_i + 1}, …, a_{r_i}).

Input

The first line contains two integers n and q (2 ≤ n ≤ 194 598, 1 ≤ q ≤ 1 049 658) — the length of the array and the number of queries.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 5 032 107) — the elements of the array.

Each of the next q lines contains two integers l_i and r_i (1 ≤ l_i < r_i ≤ n) — the parameters of a query.

Output

Output q lines — the answers for each query in the order they are given in the input.

Example

Input

10 10
34 37 28 16 44 36 43 50 22 13
1 3
4 8
6 10
9 10
3 10
8 9
5 6
1 4
1 7
2 6


Output

2
0
1
3
0
1
1
1
0
0

Note

In the first query of the first sample you can multiply second number by 7 to get 259 and multiply the third one by 37 to get 1036. Then a_2 ⋅ a_3 = 268 324 = 518^2.

In the second query subarray is already good because a_4 ⋅ a_6 = 24^2.

In the third query you can divide 50 by 2 to get 25. Then a_6 ⋅ a_8 = 30^2.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &first, T2 second) {
  if (first > second) first = second;
}
template <typename T1, typename T2>
inline void chkmax(T1 &first, T2 second) {
  if (first < second) first = second;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
  _out << "(" << _p.first << ' ' << _p.second << ")";
  return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.first >> _p.second;
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) {
    return _out;
  }
  _out << _v.front();
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
const int N = 2e5 + 1;
int n, m;
unordered_map<int, int> who[8];
int a[N];
vector<int> p[N];
int L[N][15];
const int M = 1e4 + 1;
vector<int> prime;
bool cool[M];
const int Q = 1e9 + 7;
vector<pair<int, int>> ask;
vector<int> ans;
const int LOG = 20;
int g[N];
int t[LOG][N];
int get(int L, int R) {
  --L;
  int s = g[R - L] - 1;
  return max(t[s][L], t[s][R - (1 << s)]) + 1;
}
int main() {
  ios::sync_with_stdio(0);
  for (int i = 2; i < M; ++i) {
    if (cool[i]) continue;
    prime.push_back(i);
    for (int j = i * i; j < M; j += i) {
      cool[j] = true;
    }
  }
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    for (auto j : prime) {
      if (j * j > a[i]) break;
      int cnt = 0;
      while (a[i] % j == 0) {
        ++cnt;
        a[i] /= j;
      }
      if (cnt & 1) p[i].push_back(j);
    }
    if (a[i] != 1) p[i].push_back(a[i]);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 15; ++j) {
      L[i][j] = -1e9;
    }
    for (int j = 0; j < (1 << p[i].size()); ++j) {
      int s = p[i].size();
      int hash = 1;
      for (int q = 0; q < p[i].size(); ++q) {
        if ((j >> q) & 1) {
          hash *= p[i][q];
          --s;
        }
      }
      for (int q = 0; q <= 7; ++q) {
        if (who[q].count(hash)) {
          chkmax(L[i][q + s], who[q][hash]);
        }
      }
      who[s][hash] = i;
    }
  }
  for (int i = 1; i < N; ++i) {
    g[i] = g[i >> 1] + 1;
  }
  ask.resize(m);
  ans.resize(m, 11);
  cin >> ask;
  for (int w = 0; w < 11; ++w) {
    for (int i = 0; i < n; ++i) t[0][i] = L[i][w];
    for (int j = 0; (1 << j) < n; ++j) {
      for (int q = 0; q + (1 << j) < n; ++q) {
        t[j + 1][q] = max(t[j][q], t[j][q + (1 << j)]);
      }
    }
    for (int i = 0; i < m; ++i) {
      if (get(ask[i].first, ask[i].second) >= ask[i].first) {
        chkmin(ans[i], w);
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    cout << ans[i] << '\n';
  }
}