N,X = map(int,input().split()) A = list(map(int,input().split())) B = A + A S = sum(A) import sys if S <= X: print(S) exit() l = 0 now = 0 r = 0 ans = 0 while l < N: while r < N + N and now + B[r] <= X: now += B[r] r += 1 if now > ans: ans = now if r == l: l += 1 r += 1 else: now -= B[l] l += 1 print(ans)