#!/usr/bin/env python3
def main():
    import numpy as np

    N, K = map(int, input().split())
    num_max = 3 * 10 ** 5 + 1
    numbers = np.zeros(num_max, dtype=np.int64)
    for _ in range(N):
        a = int(input())
        numbers[a] += 1

    ans = 0
    for index, num in enumerate(numbers):
        if num == 0:
            continue
        ans = max(numbers[index - K:index + K].sum(), ans)
    print(ans)


if __name__ == '__main__':
    main()
