package net.ipipip0129.yukicoder.no617; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String line = scan.nextLine(); int count = Integer.parseInt(line.split(" ")[0]); int maxweight = Integer.parseInt(line.split(" ")[1]); List stocks = new ArrayList(); for (int i = 0; i < count; i++) { stocks.add(Integer.parseInt(scan.nextLine())); } scan.close(); int cw = 0; for (int i = stocks.size() - 1; 0 <= i; i--) { if (cw + stocks.get(i) <= maxweight) { cw += stocks.get(i); } } System.out.println(cw); } }