#include int main () { int n = 0; long long x = 0LL; long long a[200000] = {}; 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); 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 { if (idx%n == i) { tmp = a[i]; idx = i+1; } while (idx%n != i && a[idx%n]+tmp <= x) { tmp += a[idx%n]; idx++; } if (tmp > ans) { ans = tmp; } tmp -= a[i]; } } printf("%lld\n", ans); return 0; }