import java.io.*; import java.util.*; public class Main_yukicoder617 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int max = 0; for (int i = 0; i < 0x1 << n; i++) { int sum = 0; for (int j = 0; j < n; j++) { if ((i & 0x1 << j) != 0) { sum += a[j]; } } if (sum <= k) { max = Math.max(max, sum); } } pr.println(max); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }