// Arup Guha
// 3/9/2021
// Solution to 2020 SER Regional Problem B: Bad Packing

import java.util.*;

public class badpacking {

	public static int n;
	public static int target;
	public static ArrayList<Integer> vals;
	public static int[] total;
	
	public static void main(String[] args) {
	
		// Get basic data.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		target = stdin.nextInt();
		
		// Store # in reverse order.
		vals = new ArrayList<Integer>();
		for (int i=0; i<n; i++) vals.add(stdin.nextInt());
		Collections.sort(vals);
		
		// Ta da!
		System.out.println(go());
	}
	
	public static int go() {
		
		// dp[k] will store largest consecutive index from beginning that forms this set.
		int[] dp = new int[target+1];
		Arrays.fill(dp, -2);
		dp[0] = -1;
		
		// Considering items from least to most.
		for (int i=0; i<n; i++) {
			
			// Go backwards here so item isn't repeated.
			for (int j=target; j>=vals.get(i); j--) {
				
				// Consecutive build.
				if (dp[j-vals.get(i)] == i-1) dp[j] = i;
				
				// Not consecutive, so take the best from what we already have and building off the old one.
				else if (dp[j-vals.get(i)] > -2) dp[j] = Math.max(dp[j-vals.get(i)], dp[j]);
			}
		}
		
		int res = target;
		
		// Find the smallest one where if we add the smallest missing item, it goes over.
		for (int i=target; i>=0; i--) {
			if (dp[i] == -2) continue;
			if (dp[i] == n-1) { res = i; break; }
			if (i + vals.get(dp[i]+1) > target) res = i;
		}
		
		// Ta da!
		return res;
	}
}