public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner scan = new Scanner(System.in);
        ArrayList<Integer> coins = new ArrayList<Integer>();
        int change = 0;
        while(scan.hasNext()){
            String tmp[] = scan.next().split(",");
            if(scan.hasNext()){
                coins.add(Integer.parseInt(tmp[0]));
            } else {
                change = Integer.parseInt(tmp[0]);
            }
        }
        System.out.println(coinchange(quickSort(coins,0,coins.size()-1),change));
    }