#include<iostream>
#include<set>
#include<unordered_map>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int tmp;
    set<int> input;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        input.insert(tmp);
    }
    unordered_map<int, int> hashmap;
    int count = 0;
    for (auto i = input.begin(); i != input.end(); i++)
    {
        if (hashmap[*i - k] == *i)
            count++;
        else
            hashmap[*i - k] = *i;
        if (hashmap[*i] == *i + k)
            count++;
        else
            hashmap[*i] = *i + k;
    }
    cout << count;
    return 0;
}