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>
#pragma GCC optimize("O3")
using namespace std;
const int MX = 6000000;
const int N = 200000;
const int Q = 1200000;
int n, tests;
int pr[MX];
int ar[N];
int last_entry[MX][8];
int le[N][15];
vector<pair<int, int> > events[N];
vector<int> queries[N];
int t[N * 4];
int ans[Q];
void build(int v, int tl, int tr) {
  t[v] = 1e9;
  if (tl == tr) {
    return;
  }
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  build(v * 2, tl, sdfjahlfasfh);
  build(v * 2 + 1, sdfjahlfasfh + 1, tr);
}
int get(int v, int tl, int tr, int l, int r) {
  if (l > r) return 1e9;
  if (tl == l && tr == r) return t[v];
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  return min(get(v * 2, tl, sdfjahlfasfh, l, min(r, sdfjahlfasfh)),
             get(v * 2 + 1, sdfjahlfasfh + 1, tr, max(sdfjahlfasfh + 1, l), r));
}
void update(int v, int tl, int tr, int ps, int val) {
  if (tl == tr) {
    t[v] = min(t[v], val);
    return;
  }
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  if (ps <= sdfjahlfasfh)
    update(v * 2, tl, sdfjahlfasfh, ps, val);
  else
    update(v * 2 + 1, sdfjahlfasfh + 1, tr, ps, val);
  t[v] = min(t[v * 2], t[v * 2 + 1]);
}
vector<int> get_primes(int val) {
  vector<int> ret;
  while (val > 1) {
    int x = pr[val];
    int cnt = 0;
    while (val % x == 0) {
      val /= x;
      cnt++;
    }
    if (cnt % 2) ret.push_back(x);
  }
  return ret;
}
int l[Q], r[Q];
int naive(int l, int r) {
  int res = 1e9;
  for (int i = l; i <= r; i++) {
    for (int j = 0; j < 15; j++) {
      if (le[i][j] >= l) res = min(res, j);
    }
  }
  return res;
}
int main() {
  scanf("%d", &n);
  scanf("%d", &tests);
  pr[1] = 1;
  for (int i = 2; i < MX; i++) {
    if (pr[i] == 0) {
      for (int j = i; j < MX; j += i) {
        pr[j] = i;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
  }
  for (int i = 1; i < MX; i++) {
    for (int j = 0; j <= 7; j++) {
      last_entry[i][j] = -1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 15; j++) {
      le[i][j] = -1;
    }
    vector<int> v = get_primes(ar[i]);
    for (int mask = 0; mask < (1 << v.size()); mask++) {
      int val = 1;
      int pc = 0;
      for (int j = 0; j < v.size(); j++) {
        if (mask & (1 << j)) {
          val *= v[j];
          pc++;
        }
      }
      for (int q = pc; q <= 7; q++) {
        if (last_entry[val][q] == -1) continue;
        int cost = q + v.size() - 2 * pc;
        le[i][cost] = max(le[i][cost], last_entry[val][q]);
      }
    }
    for (int mask = 0; mask < (1 << v.size()); mask++) {
      int val = 1;
      int pc = 0;
      for (int j = 0; j < v.size(); j++) {
        if (mask & (1 << j)) {
          val *= v[j];
          pc++;
        }
      }
      last_entry[val][v.size()] = i;
    }
  }
  for (int test = 1; test <= tests; test++) {
    scanf("%d", &l[test]);
    scanf("%d", &r[test]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 15; j++) {
      if (le[i][j] != -1) {
        int ps = le[i][j];
        events[ps].push_back(make_pair(i, j));
      }
    }
  }
  for (int i = 1; i <= tests; i++) {
    queries[l[i]].push_back(i);
  }
  build(1, 1, n);
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j < events[i].size(); j++) {
      int ps = events[i][j].first;
      int val = events[i][j].second;
      update(1, 1, n, ps, val);
    }
    for (int j = 0; j < queries[i].size(); j++) {
      int id = queries[i][j];
      int here = get(1, 1, n, l[id], r[id]);
      ans[id] = here;
    }
  }
  for (int i = 1; i <= tests; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}