import sys #input = sys.stdin.readline input = sys.stdin.buffer.readline #文字列はダメ #sys.setrecursionlimit(1000000) #import bisect #import itertools #import random #from heapq import heapify, heappop, heappush #from collections import defaultdict #from collections import deque #import copy #import math #from functools import lru_cache #@lru_cache(maxsize=None) #MOD = pow(10,9) + 7 #MOD = 998244353 #dx = [1,0,-1,0] #dy = [0,1,0,-1] def solve(A,K): N = len(A) dp = [[0]*(K+1) for _ in range(N+1)] dp[0][0] = 1 #配るDP for i in range(N): a = A[i] for j in range(K+1): #使わない場合 dp[i+1][j] = max(dp[i+1][j], dp[i][j]) #使う場合 if j+a <= K: dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j]) used = [] if dp[N][K] == 0: return used v = K for i in reversed(range(N)): a = A[i] if v-a >= 0 and dp[i][v-a] == 1: used.append(i) v -= a return used def main(): N,K = map(int,input().split()) A = list(map(int,input().split())) mx = [-1]*(1+K) mn = [-1]*(1+K) A.sort() for i,a in enumerate(A): if mn[a] == -1: mn[a] = i mx[a] = i X = solve(A,K) X.sort() #print(X) A.reverse() Y = solve(A,K) Y = sorted([N-1-y for y in Y]) #print(X,Y) #print(mx) #print(mn) #print(Y) X = set(X) Y = set(Y) Z = X&Y if len(Z) == 0: print(-1);exit() ans = 0 for v in range(1+K): if mx[v] == -1: continue num = mx[v] - mn[v] + 1 #値vはnum個ある if mx[v] in Z and mn[v] in Z: ans += num print(ans) if __name__ == '__main__': main()