def main(): N,K = input().split() N = int(N) K = int(K) goods = [] for i in range(N): goods.append(int(input())) totals = [] tmp = 0 for j in range(N-1,-1,-1): for l in range(j,-1,-1): if K-tmp >= goods[l]: tmp+=goods[l] totals.append(tmp) print(max(totals)) main()