import java.util.*;
import java.io.*;
/**
* Datatähti 2021 alku
* Alitaulukot/Subtables
* @author TRS
*/
public class Alitaulukot {
//Constants
static final int infinity = 0x3f3f3f3f;
static final long linfinity = 0x3f3f3f3f3f3f3f3fL;
static final int MOD = 1000000007;
//Input
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
public static void main(String[] args) throws IOException {
int n = readInt();
int k = readInt();
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = readInt();
}
System.out.println(solve(array, k));
}
static int solve(int[] array, int k) {
int answer = 0;
int i = 0;
int minimum = array[0];
int maximum = array[0];
List<Integer> ascend = new ArrayList<Integer>();
List<Integer> descend = new ArrayList<Integer>();
ascend.add(0);
descend.add(0);
for (int j = 1; j < array.length; j++) {
int value = array[j];
while (ascend.size() > 0 && array[ascend.get(ascend.size() - 1)] > value) {
ascend.remove(ascend.size() - 1);
}
while (descend.size() > 0 && array[descend.get(descend.size() - 1)] < value) {
descend.remove(descend.size() - 1);
}
ascend.add(j);
descend.add(j);
if (array[j] > maximum) {
maximum = array[j];
if (maximum - minimum > k) {
while (maximum - array[ascend.get(0)] > k) {
ascend.remove(0);
}
i = ascend.get(0);
minimum = array[i];
while (descend.get(0) < i) {
descend.remove(0);
}
}
}
else if (array[j] < minimum) {
minimum = array[j];
if (maximum - minimum > k) {
while (array[descend.get(0)] - minimum > k) {
ascend.remove(0);
}
i = descend.get(0);
maximum = array[i];
while (ascend.get(0) < i) {
ascend.remove(0);
}
}
}
answer += j - i + 1;
}
answer++;
return answer;
}
static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine().trim());
}
return st.nextToken();
}
static long readLong() throws IOException {
return Long.parseLong(next());
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
static double readDouble() throws IOException {
return Double.parseDouble(next());
}
static char readCharacter() throws IOException {
return next().charAt(0);
}
static String readLine() throws IOException {
return br.readLine().trim();
}
}