//大一大二看起来毫无思路的问题,现在积累多了却很容易解决
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int maxLen(int *a, int start, int end, int k)
{
//special case
if( k==0 )
{
return 1;
}
if( k < 0 )
{
return 0;
}
if( start == end )
{
return 1;
}
int mid = start + (end - start)/2;
int leftMaxLen = maxLen(a, start, mid, k);
int rightMaxLen = maxLen(a, mid+1, end, k);
//left part
int crossLen = 0;
int maxValue = a[mid], minValue = a[mid];
for( int i = mid; i >= start ; i-- )
{
int tmpMaxValue = maxValue, tmpMinValue = minValue;
if( a[i] > maxValue )
{
maxValue = a[i];
}
if( a[i] < minValue )
{
minValue = a[i];
}
if( maxValue - minValue <= k )
{
crossLen++;
}
else
{
maxValue = tmpMaxValue;
minValue = tmpMinValue;
break;
}
}
for( int j = mid+1; j <= end ; j++ )
{
if( a[j] > maxValue )
{
maxValue = a[j];
}
if( a[j] < minValue )
{
minValue = a[j];
}
if( maxValue - minValue <= k )
{
crossLen++;
}
else
{
break;
}
}
return max(leftMaxLen, max(rightMaxLen, crossLen));
}
int main(int argc, char *argv[])
{
int n;
int k;
scanf("%d %d", &n, &k);
int a[30000];
for( int i = 0; i < n ; i++ )
{
scanf("%d", &a[i]);
}
printf("%d\n", maxLen(a, 0, n-1, k));
return 0;
}