N, X = map(int, input().split()) A = list(map(int, input().split())) if sum(A) < X: exit(print(sum(A))) if min(A) > X: exit(print(0)) acc = [0] * (2 * N + 1) for i in range(2 * N): acc[i + 1] = acc[i] + A[i % N] ans = 0 for i in range(N): ok = i; ng = i + N + 1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if acc[mid] - acc[i] < X: ok = mid else: ng = mid ans = max(ans, acc[ok] - acc[i]) print(ans)