#include int main () { int n = 0; long long x = 0LL; long long a[400000] = {}; int res = 0; long long ans = 0LL; long long tmp = 0LL; int idx = 0; res = scanf("%d", &n); res = scanf("%lld", &x); for (int i = 0; i < n; i++) { res = scanf("%lld", a+i); a[i+n] = a[i]; ans += a[i]; } if (ans <= x) { printf("%lld\n", ans); return 0; } ans = 0LL; for (int i = 0; i < n; i++) { if (a[i] > x) { tmp = 0LL; idx = i+1; } else { while (idx < i+n && a[idx]+tmp <= x) { tmp += a[idx]; idx++; } if (tmp > ans) { ans = tmp; } tmp -= a[i]; } } printf("%lld\n", ans); return 0; }