// Arup Guha
// 5/21/2021
// Solution to 2021 SER Problem O: TripTik

import java.util.*;

public class triptik {

	public static int n;
	public static int limit;
	public static int[] vals;
	public static int[] copyV;
	public static HashMap<Integer,Integer> map;
	public static int[] indexMap;

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		limit = stdin.nextInt();
		vals = new int[n+1];
		copyV = new int[n+1];
		
		// Mapping location to "flipped" index size.
		map = new HashMap<Integer,Integer>();
		map.put(0, 0);
		for (int i=1; i<=n; i++) {
			vals[i] = stdin.nextInt();
			copyV[i] = vals[i];
			map.put(vals[i], -i);
		}
		
		// Sort this so we can sweep from left to right.
		Arrays.sort(vals);
		indexMap = new int[n+1];
		for (int i=0; i<=n; i++)
			indexMap[i] = -map.get(vals[i]);
		
		// Will store all of the largest targets. So lists[i] represents a window of size (1<<i).
		ArrayList<Integer>[][] lists = new ArrayList[29][n+1];
		for (int i=0; i<29; i++)
			for (int j=0; j<=n; j++)
				lists[i][j] = new ArrayList<Integer>(limit);
		
		// Find best neighbors for each radius, from 1 to (1<<28).
		for (int i=0; i<29; i++) {
			
			// Pointer for sweep.
			int high = 0;
			PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
			
			// j will be the center of our zone.
			for (int j=0; j<=n; j++) {
				
				// Sweep forward, adding new items into the heap.
				while (high < n+1 && vals[high] <= vals[j]+(1<<i)) {
					pq.offer(map.get(vals[high]));
					high++;
				}
				
				// Now remove the best items from the PQ until we get to our limit or it's empty.
				int added = 0;
				while (added < limit && pq.size() > 0) {
					
					// next item.
					int item = pq.poll();
					
					// The item is no longer in range, so we don't add it.
					if (copyV[-item] < vals[j]-(1<<i)) continue;
					
					// This item is in range. Add it.
					lists[i][indexMap[j]].add(item);
					added++;
				}			
				
				// Put these items back into the PQ.
				for (Integer x: lists[i][indexMap[j]])
					pq.offer(x);
			} // end j
		} // end i
		
		// Stored based on original indexes.
		int[][] dist = new int[29][n+1];
		for (int i=0; i<29; i++) Arrays.fill(dist[i], -1);
		dist[0][0] = 0;
		
		// Start the BFS. State = (node<<5) + level.
		LinkedList<Integer> q = new LinkedList<Integer>();
		q.offer(0);
		
		// Run BFS.
		while (q.size() > 0) {
			
			// Get the current state.
			int cur = q.pollFirst();
			int node = (cur >> 5);
			int level = (cur & 31);
			
			// Zoom out.
			if (level < 28 && dist[level+1][node] == -1) {
				dist[level+1][node] = dist[level][node]+1;
				q.offer((node<<5)+level+1);
			}
			
			// Zoom in.
			if (level > 0 && dist[level-1][node] == -1) {
				dist[level-1][node] = dist[level][node]+1;
				q.offer((node<<5)+level-1);
			}
			
			// Change focus - only add to queue if we've never been here before.
			for (Integer x: lists[level][node]) {
				if (dist[level][-x] == -1) {
					dist[level][-x] = dist[level][node]+1;
					q.offer(((-x)<<5) + level);
				}
			}
		}
		
		// Store answer here.
		int[] res = new int[n+1];
		Arrays.fill(res, -1);
		StringBuffer sb = new StringBuffer();
		
		// Just find the best answer for any level of zoom.
		for (int i=1; i<=n; i++) {
			
			// Try all levels and get the best answer.
			for (int lev=0; lev<29; lev++) {
				
				// Never got to this level to this target.
				if (dist[lev][i] == -1) continue;
				
				// Tricky case. We zoomed here to radius 1 and can't see ourselves, so we must go radius=1/2.
				if (lev == 0 && !lists[lev][i].contains(-i)) {
					if (res[i] == -1 || dist[lev][i]+1 < res[i]) 
						res[i] = dist[lev][i]+1;
				}
				
				// I can't see you!
				if (!lists[lev][i].contains(-i)) continue;
				
				// If we get here, we are the center and can be seen.
				if (res[i] == -1 || dist[lev][i] < res[i]) 
					res[i] = dist[lev][i];
			}
			sb.append(res[i]+"\n");
		}
		System.out.print(sb);
	}
}