from bisect import * n, x = map(int, input().split()) a = list(map(int, input().split())) b = a + a acc = [0] for i in b: acc.append(acc[-1] + i) ans = 0 # print(acc) for i in range(n): ind = bisect_left(acc, acc[i] + x) if ind == len(acc): num = sum(a) elif acc[ind] == acc[i + 1] + x: num = acc[ind] - acc[i] else: num = acc[ind - 1] - acc[i] num = min(sum(a), num) # print(ind) # print(num,"ans") ans = max(ans, num) print(ans)