#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, x; cin >> n >> x; vector a(n); vector s(2 * n + 1); for(int i = 0; i < n; i++){ cin >> a[i]; s[i + 1] = s[i] + a[i]; } for(int i = 0; i < n; i++) s[i + 1 + n] = s[i + n] + a[i]; ll ans = 0; for(int l = 0, r = 0; l < n; l++){ r = max(r, l); while(r <= l + n && s[r] <= s[l] + x){ ans = max(ans, s[r] - s[l]); r++; } } cout << ans << '\n'; }