import java.util.Arrays; import java.util.Scanner; public class Main { public static int [] A; public static int K; public static int max = 0; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); K = scan.nextInt(); A = new int[N]; for(int i = 0; i < N; i++) { A[i] = scan.nextInt(); } scan.close(); int []S = new int[N]; Arrays.fill(S, 0); rec(0, N, S); System.out.println(max); } public static void rec(int k, int n, int[] S) { if(k == n) { solve(S); return; } rec(k + 1, n, S); S[k] = 1; rec(k + 1,n, S); S[k] = 0; } public static void solve(int[] S) { //disp(S); int sum = 0; for(int i = 0; i < S.length; i++) { if(S[i] == 1) { sum += A[i]; } if(sum > K) { break; }else if(sum == K) { System.out.println(K); System.exit(0); }else { if(max < sum) { max = sum; } } } } public static void disp(int []A) { for(int i = 0; i < A.length - 1; i++) { System.out.print(A[i] + ", "); } System.out.println(A[A.length -1]); } }