import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int[] costlyIntervals(int n, int k, int[] A) { int[] ans = new int[n]; Arrays.fill(ans, -1); SegmentTree tree = new SegmentTree(A, k); int[] end = new int[n]; for (int i = 0; i < n; i++) { end[i] = i; } for (int i = 0; i < n - 1; ++i) { for (int j = n - 1; j > end[i]; --j) { int cost = tree.getCost(i, j); if (cost >= k) { int dist = j - i + 1; for (int v = i; v <= j; v++) { end[v] = Math.max(j, end[v]); ans[v] = Math.max(ans[v], dist); } } } } return ans; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int[] A = new int[n]; for(int A_i = 0; A_i < n; A_i++){ A[A_i] = in.nextInt(); } int[] result = costlyIntervals(n, k, A); for (int i = 0; i < result.length; i++) { System.out.print(result[i] + (i != result.length - 1 ? "\n" : "")); } System.out.println(""); in.close(); } static class SegmentTree { int n, k; int[] arr; int[] or, and, max, min, cost; public static final int AND = (1 << 30) - 1; public SegmentTree (int[] a, int k) { this.k = k; this.n = a.length; this.arr = a; int size = Integer.highestOneBit(n) << 2; or = new int[size]; and = new int[size]; max = new int[size]; min = new int[size]; buildTree(1, 0, n - 1, a); } private void buildTree(int node, int l, int r, int[] a) { if (l > r) return; if (l == r) { or[node] = a[l]; and[node] = a[l]; max[node] = a[l]; min[node] = a[l]; return; } int mid = l + r >> 1; int left = node << 1; int right = node << 1 | 1; buildTree(left, l, mid, a); buildTree(right, mid + 1, r, a); or[node] = or[left] | or[right]; and[node] = and[left] & and[right]; max[node] = Math.max(max[left], max[right]); min[node] = Math.min(min[left], min[right]); } public int getCost(int l, int r) { int cost = getOr(1, 0, n - 1, l, r) - getAnd(1, 0, n - 1, l, r) - getMax(1, 0, n - 1, l, r) + getMin(1, 0, n - 1, l, r); return cost; } private int getOr(int node, int l, int r, int s, int e) { if (l > r || l > e || r < s) return 0; if (s <= l && r <= e) return or[node]; int mid = l + r >> 1; return getOr(node << 1, l, mid, s, e) | getOr(node << 1 | 1, mid + 1, r, s, e); } private int getAnd(int node, int l, int r, int s, int e) { if (l > r || l > e || r < s) return 0; if (s <= l && r <= e) return and[node]; int mid = l + r >> 1; if (mid < s) return getAnd(node << 1 | 1, mid + 1, r, s, e); else if (mid >= e) return getAnd(node << 1, l, mid, s, e); else return getAnd(node << 1, l, mid, s, e) & getAnd(node << 1 | 1, mid + 1, r, s, e); } private int getMax(int node, int l, int r, int s, int e) { if (l > r || l > e || r < s) return Integer.MIN_VALUE; if (s <= l && r <= e) return max[node]; int mid = l + r >> 1; return Math.max(getMax(node << 1, l, mid, s, e), getMax(node << 1 | 1, mid + 1, r, s, e)); } private int getMin(int node, int l, int r, int s, int e) { if (l > r || l > e || r < s) return Integer.MAX_VALUE; if (s <= l && r <= e) return min[node]; int mid = l + r >> 1; return Math.min(getMin(node << 1, l, mid, s, e), getMin(node << 1 | 1, mid + 1, r, s, e)); } } }