N, K = map(int, input().split()) A = list(map(int, input().split())) dpl = [0 for _ in range(N + 1)] dpr = [0 for _ in range(N + 1)] dpl[0] = 1 dpr[N] = (1 << K) for i in range(N): dpl[i + 1] = dpl[i] | (dpl[i] << A[i]) for i in range(N - 1, -1, -1): dpr[i] = dpr[i + 1] | (dpr[i + 1] >> A[i]) if (dpl[N] & (1 << K)) == 0: print(-1) else: ans = N for i in range(N): if dpl[i] & dpr[i + 1]: ans -= 1 print(ans)