/*
    author: Tran Van Nam
    Nguyen Trai High School - Quang Binh
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 1e7 + 5;;
const int INF = 1e9;

int a[N], phi[N];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    // freopen("SUBARR.INP", "r", stdin);
    // freopen("SUBARR.OUT", "w", stdout);

    for (int i = 1; i < N; i++) phi[i] = i;
    for (int i = 2; i*i < N; i++)
        if (phi[i] == i)
            for (int j = i; i*j < N; j++) phi[i*j] = i;

    int n, k; cin >> n >> k;
    for (int i = 1; i <= n; i++){
        int x; cin >> x;
        a[i] = 1;
        while (x > 1){
            int divisor = phi[x];
            int cnt = 0;
            while (x % divisor == 0){
                cnt++;
                x /= divisor;
            }
            a[i] *= (cnt + 1);
        }
    }

    int d = 0;
    for (int i = 1; i <= n; i++) d = max(d, a[i]);

    int ans = INF, sum = 0;
    for (int l = 1, r = 1; r <= n; r++){
        sum += (a[r] == d);
        while (sum >= k){
            ans = min(ans, r - l + 1);
            sum -= (a[l] == d);
            l++;
        }
    }

    if (ans == INF) cout << -1; else cout << ans;

    return 0^0;
}