from itertools import accumulate import sys def printe(*args, end="\n", **kwargs): print(*args, end=end, file=sys.stderr, **kwargs) def main(): N, X = map(int, input().split()) A = list(map(int, input().split())) if sum(A) <= X: print(sum(A)) return A_cp = [0] A_cp.extend(A) A_cp.extend(A) accum_A = list(accumulate(A_cp)) printe(accum_A) max_value = 0 for init_idx in range(N): lower = init_idx upper = init_idx + N while upper - lower > 1: mid = (upper + lower) // 2 if accum_A[mid] - accum_A[init_idx] > X: upper = mid else: lower = mid max_value = max(max_value, accum_A[lower] - accum_A[init_idx]) print(max_value) if __name__ == "__main__": main()