package tmp; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); int[] A = new int[N]; for (int i = 0; i < N; ++i) { A[i] = sc.nextInt(); } Arrays.sort(A); int ans = 0; for (int i = A.length - 1; i >= 0; --i) { if (ans + A[i] > K) continue; else { ans += A[i]; } } System.out.println(ans); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }