#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+14;
int n, s, f[maxn];
unordered_map < int , int > m;
void solve(){
cin >> n >> s;
f[0] = 0;
int ans = n + 1;
for (int i = 1; i <= n; i++){
int x;
cin >> x;
f[i] = f[i - 1] + x;
m[f[i]] = i;
if (f[i] == s) {
ans = min(ans, i - m[0]);
}
else {
if (m[f[i] - s]) {
ans = min(ans, i - m[f[i] - s]);
}
}
}
if (ans == n + 1) {
cout << -1;
}
else cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen("input.txt","r")){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBtYXhuPTFlNisxNDsKaW50IG4sIHMsIGZbbWF4bl07CnVub3JkZXJlZF9tYXAgPCBpbnQgLCBpbnQgPiBtOwp2b2lkIHNvbHZlKCl7CgljaW4gPj4gbiA+PiBzOwoJZlswXSA9IDA7CglpbnQgYW5zID0gbiArIDE7Cglmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspewoJCWludCB4OwoJCWNpbiA+PiB4OwoJCWZbaV0gPSBmW2kgLSAxXSArIHg7CgkJbVtmW2ldXSA9IGk7CgkJCgkJaWYgKGZbaV0gPT0gcykgewoJCQlhbnMgPSBtaW4oYW5zLCBpIC0gbVswXSk7CgkJfQoJCWVsc2UgewoJCQlpZiAobVtmW2ldIC0gc10pIHsKCQkJCWFucyA9IG1pbihhbnMsIGkgLSBtW2ZbaV0gLSBzXSk7CgkJCX0KCQl9Cgl9CglpZiAoYW5zID09IG4gKyAxKSB7CgkJY291dCA8PCAtMTsKCX0KCWVsc2UgY291dCA8PCBhbnM7Cn0KaW50IG1haW4oKXsKCWlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CgljaW4udGllKDApOyAgICBjb3V0LnRpZSgwKTsKCWlmIChmb3BlbigiaW5wdXQudHh0IiwiciIpKXsKCQlmcmVvcGVuKCJpbnB1dC50eHQiLCJyIixzdGRpbik7CgkJZnJlb3Blbigib3V0cHV0LnR4dCIsInciLHN0ZG91dCk7Cgl9Cglzb2x2ZSgpOwoJcmV0dXJuIDA7Cn0K