import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) N,K = mi() A = li() assert N <= 10**4 assert K <= 10**3 dp = [0 for i in range(N+1)] dp[0] = 1 for i in range(N): dp[i+1] = dp[i]|(dp[i]<>K & 1 == 0: exit(print(-1)) need = 0 for i in range(N): flag = True for k in range(K+1): if dp[i]>>k & 1: if dp_back[i+1]>>(K-k) & 1: flag = False if flag: need += 1 print(need)