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

    N, K = map(int, input().split())
    num_max = 3 * 10 ** 5
    numbers = np.zeros(num_max + 2, dtype=np.int64)
    for _ in range(N):
        a = int(input())
        a -= 1
        if a - K >= 0:
            left = a - K
        else:
            left = 0
        if a + K < N:
            right = a + K
        else:
            right = -1
        numbers[left] += 1
        numbers[right] -= 1

    ans = 0
    res = 0
    for i in range(num_max + 1):
        res += numbers[i]
        if ans < res:
            ans = res

    print(ans)


if __name__ == '__main__':
    main()
