import bisect


def solve(n: int, m: int, a: list) -> int:
    b = sorted([0] + [a[i] + a[j] for i in range(n) for j in range(n)])
    ans = -1
    for i in range(n * n):
        if b[i] > m:
            continue
        j = bisect.bisect_left(b, m - b[i])
        if b[j] != m - b[i]:
            j -= 1
        ans = max(ans, b[i] + b[j])
    return ans


n, m = map(int, input().split())
a = [int(input()) for _ in range(n)]
print(solve(n, m, a))
