using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0041
{
    class Program
    {
        static void Main(string[] args)
        {
            var rStr = Console.ReadLine();

            int N = int.Parse(rStr.Split(' ')[0]);
            int K = int.Parse(rStr.Split(' ')[1]);


            int[] r = new int[N];
            for (int i = 0; i < N; i++)
            {
                r[i] = int.Parse(Console.ReadLine());
            }

            int Ma = 0;
            for (int i = 0; i < N - 1; i++)
            {
                int result = 0;

                for (int j = i + 1; j < N; j++)
                {
                    if (Math.Abs(r[i] - r[j]) <= K)
                    {
                        result++;
                    }
                }

                if (Ma <= result)
                {
                    Ma = result;
                }
            }
         
            Console.WriteLine(Ma);

        }
    }
}
