package m.shin; import java.util.Scanner; import java.util.TreeSet; public class Con617 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int N = s.nextInt() , K = s.nextInt(); TreeSet A = new TreeSet<>(); for(int i = 0;i < N;i++){ A.add(s.nextInt()); } s.close(); Integer[] a = new Integer[A.size()]; A.toArray(a); //System.out.println(a[0] + " " + a[1]); int max = 0; int[][] d = new int[K+1][2]; //[合計値][次に足すaの番号] d[0][0] = 1; for(int i = 0;i <= K;i++){ if(d[i][0] == 1){ for(int j = d[i][1];j < N;j++){ int add = a[j]; if(i + add <= K){ d[i + add][0] = 1; d[i + add][1] = Math.min(j+1, N); max = Math.max(max, i + add); } } } } System.out.println(max); } }