// Arup Guha
// 3/5/2022
// Solution to 2021 SER D1/D2 Problem: Tournament Seeding

import java.util.*;
import java.io.*;

public class tournament {

	public static ArrayList<Integer> vals;
	public static int maxD;
	
	public static void main(String[] args) throws Exception {
	
		BufferedReader stdin =  new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		
		// Get basic params.
		int n = Integer.parseInt(tok.nextToken());
		maxD = Integer.parseInt(tok.nextToken());
		
		// Get array.
		vals = new ArrayList<Integer>();
		for (int i=0; i<(1<<n); i++) 
			vals.add(Integer.parseInt(stdin.readLine()));
		
		// Sort from largest to smallest.
		Collections.sort(vals);
		Collections.reverse(vals);
		
		int res = 0;
		
		// (1<<size) represents the # of winning teams in that round.
		for (int size=0; size<n; size++) {
			res += round(size);
		}
		
		// Ta da!
		System.out.println(res);
	}
	
	public static int round(int size) {
	
		int res = 0;
		
		// Pointer for sweep.
		int high = (1<<size);
		
		// Just match the ones that you can, starting with the highest.
		for (int low=0; low<(1<<size); low++) {
			if (vals.get(low) - vals.get(high) <= maxD) {
				res++;
				high++;
			}
		}
		
		// Ta da!
		return res;
	}
}