N, X = map(int, input().split()) A = list(map(int, input().split())) B = A + A r = 0 now = 0 ans = 0 for l in range(2 * N): while l > r: now += B[r] r += 1 while r < 2 * N and now + B[r] <= X: now += B[r] r += 1 ans = max(ans, now) now -= B[l] print(ans)