def solve(n, x, a): if n == 1: return a[0] if a[0] <= x else 0 ans = 0 r = 1 s = 0 for l in range(1, n - 1): while r < n - 1 and s + a[r] <= x: s += a[r] r += 1 if s <= x: ans = max(s, ans) s -= a[l] r = 0 s = sum(a) for l in range(n): while r <= l and s + a[r] <= x: s += a[r] r += 1 if s <= x: ans = max(s, ans) s -= a[l] return ans n, x = [int(y) for y in input().split()] a = [int(y) for y in input().split()] print(solve(n, x, a))