#include #include #include using namespace std; using ll = long long; #define REP(i, n) for(ll i=0; i<(n);i++) int main() { ll n, x; cin >> n >> x; vector a(n); REP(i, n) cin >> a[i]; ll m = 0; REP(i, n) m += a[i]; vector sum(n * 2 + 1); REP(i, n * 2) sum[i + 1] = sum[i] + a[i % n]; ll ans = 0; REP(i, n) { auto it = lower_bound(sum.begin(), sum.end(), x + sum[i] + 1); it--; ll tmp = *it - sum[i]; ans = max(min(tmp, m), ans); } cout << ans; return 0; }