

def solve(n, d, arr):

    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            temp = abs(arr[j] - arr[i])
            if ans < temp <= d:
                ans = temp

    print(ans)


# Main
def run():
    n, d = map(int, input().split())
    arr = list(map(int, input().split()))

    if len(arr) == 1:
        print(0)
    else:
        solve(n, d, arr)

# end main


# Program Start
if __name__ == "__main__":
    run()