#include "bits/stdc++.h"

using namespace std;
#define int long long
#define endl "\n"
#define PII pair<int,int>
#define PIII pair<int,PII>
const int MOD = 1e9 + 7;
const int N = 3e5;

void slu() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1, 0);
    unordered_map<int, int> m;
    int res = 0;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] -= k;
        a[i] += a[i - 1];
        if (a[i] == 0) res = max(res, i);
        else if (m[a[i]]) {
            res = max(res, i - m[a[i]]);
        } else {
            m[a[i]] = i;
        }
    }
    if (!res)res = -1;
    cout << res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
//    cin >> T;
    T = 1;
    while (T--)slu();

}