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;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double pi = acos(-1.0);
const int maxn = 200000 + 10;
const int mod = 1e9 + 7;
inline char _getchar() {
  static const int BUFSIZE = 100001;
  static char buf[BUFSIZE];
  static char *psta = buf, *pend = buf;
  if (psta >= pend) {
    psta = buf;
    pend = buf + fread(buf, 1, BUFSIZE, stdin);
    if (psta >= pend) return -1;
  }
  return *psta++;
}
inline int read(int &x) {
  x = 0;
  int f = 1;
  char ch = _getchar();
  while ((ch < '0' || ch > '9') && ~ch) {
    if (ch == '-') f = -1;
    ch = _getchar();
  }
  if (ch == -1) return -1;
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = _getchar();
  }
  x *= f;
  return 1;
}
inline int read(long long &x) {
  x = 0;
  int f = 1;
  char ch = _getchar();
  while ((ch < '0' || ch > '9') && ~ch) {
    if (ch == '-') f = -1;
    ch = _getchar();
  }
  if (ch == -1) return -1;
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = _getchar();
  }
  x *= f;
  return 1;
}
inline int read(double &x) {
  char in;
  double Dec = 0.1;
  bool IsN = false, IsD = false;
  in = _getchar();
  if (in == EOF) return -1;
  while (in != '-' && in != '.' && (in < '0' || in > '9')) in = _getchar();
  if (in == '-') {
    IsN = true;
    x = 0;
  } else if (in == '.') {
    IsD = true;
    x = 0;
  } else
    x = in - '0';
  if (!IsD) {
    while (in = _getchar(), in >= '0' && in <= '9') {
      x *= 10;
      x += in - '0';
    }
  }
  if (in != '.') {
    if (IsN) x = -x;
    return 1;
  } else {
    while (in = _getchar(), in >= '0' && in <= '9') {
      x += Dec * (in - '0');
      Dec *= 0.1;
    }
  }
  if (IsN) x = -x;
  return 1;
}
inline int read(float &x) {
  char in;
  double Dec = 0.1;
  bool IsN = false, IsD = false;
  in = _getchar();
  if (in == EOF) return -1;
  while (in != '-' && in != '.' && (in < '0' || in > '9')) in = _getchar();
  if (in == '-') {
    IsN = true;
    x = 0;
  } else if (in == '.') {
    IsD = true;
    x = 0;
  } else
    x = in - '0';
  if (!IsD) {
    while (in = _getchar(), in >= '0' && in <= '9') {
      x *= 10;
      x += in - '0';
    }
  }
  if (in != '.') {
    if (IsN) x = -x;
    return 1;
  } else {
    while (in = _getchar(), in >= '0' && in <= '9') {
      x += Dec * (in - '0');
      Dec *= 0.1;
    }
  }
  if (IsN) x = -x;
  return 1;
}
inline int read(char *x) {
  char *tmp = x;
  char in = _getchar();
  while (in <= ' ' && in != EOF) in = _getchar();
  if (in == -1) return -1;
  while (in > ' ') *(tmp++) = in, in = _getchar();
  *tmp = '\0';
  return 1;
}
int pos[5032108][8];
int a[maxn];
vector<pair<int, int> > val[16];
vector<pair<int, int> > op[16];
int kb[1 << 8];
int ones[1 << 8];
int ans[1049658 + 10];
int anss[1049658 + 10];
int tree[maxn << 2];
int q[((1049658 + 10) << 1) + maxn * 8];
int L[1049658 + 10], R[1049658 + 10];
void upd(int l, int r, int pos, int x, int v) {
  tree[pos] = min(tree[pos], v);
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (x <= mid)
    upd(l, mid, pos << 1, x, v);
  else
    upd(mid + 1, r, pos << 1 | 1, x, v);
}
int query(int l, int r, int pos, int l1, int r1) {
  if (l >= l1 && r1 >= r) {
    return tree[pos];
  }
  int mid = (l + r) >> 1, ret = inf;
  if (mid >= l1) ret = query(l, mid, pos << 1, l1, r1);
  if (mid + 1 <= r1) ret = min(query(mid + 1, r, pos << 1 | 1, l1, r1), ret);
  return ret;
}
vector<pair<int, int> > A = val[0];
vector<pair<int, int> > B = op[0];
bool cmp(int a, int b) {
  if (A[a].second == A[b].second) return B[a] < B[b];
  return A[a].second < A[b].second;
}
void slove(int len) {
  memset(anss, 0, sizeof(anss));
  memset(tree, 0x3f, sizeof(tree));
  for (int i = 0; i < A.size(); i++) {
    q[i] = i;
  }
  int n = A.size();
  sort(q, q + n, cmp);
  for (int i = 0; i < n; i++) {
    int tr = B[q[i]].first;
    if (!tr) {
      upd(1, len, 1, A[q[i]].first, B[q[i]].second);
    } else {
      ans[tr] = query(1, len, 1, L[tr], R[tr]);
    }
  }
}
int main() {
  for (int i = 1; i < (1 << 8); i++) ones[i] = ones[i - (i & (-i))] + 1;
  kb[0] = 1;
  int n, q;
  read(n), read(q);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    int tmp = a[i];
    vector<int> k;
    int mx[15] = {0};
    for (int j = 2; j * j <= tmp; j++) {
      int cnt = 0;
      while (tmp % j == 0) {
        tmp /= j;
        cnt ^= 1;
      }
      if (cnt) k.push_back(j);
    }
    if (tmp != 1) k.push_back(tmp);
    int sz = k.size();
    for (int j = 0; j < sz; j++) kb[1 << j] = k[j];
    for (int j = 0; j < (1 << sz); j++) {
      kb[j] = kb[j - (j & (-j))] * kb[j & -j];
      int va = sz - ones[j];
      for (int w = 0; w < 8; w++) {
        if (pos[kb[j]][w]) {
          mx[w + va] = max(mx[w + va], pos[kb[j]][w]);
        }
      }
      pos[kb[j]][va] = i;
    }
    for (int j = 0; j <= 14; j++) {
      if (mx[j]) A.push_back(make_pair(mx[j], i)), B.push_back(make_pair(0, j));
    }
  }
  for (int i = 1; i <= q; i++) {
    read(L[i]), read(R[i]);
  }
  for (int j = 1; j <= q; j++) {
    A.push_back(make_pair(L[j], R[j])), B.push_back(make_pair(j, 1));
  }
  slove(n);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}