Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/dp-eng-kam-tangalar

Fewest coins

Medium 1000 ms 128 MB 47%
Share

There are coins of $n$ different denominations: $c_{1}, c_{2}, \dots, c_{n}$; any number of coins of each denomination may be taken. Find the smallest number of coins that add up to exactly $S$ soums. If $S$ cannot be made, print $-1$.

Making the sum S with the fewest of the given coins

Input

The first line contains two integers: $n$ and $S$. The second line contains $n$ distinct positive integers $c_{j}$.

Output

One integer — the smallest number of coins or $-1$.

Note

$1 \le n \le 50$
$0 \le S \le 10^{4}$
$1 \le c_{j} \le 10^{4}$

Examples

Input #1
3 11
1 2 5
Output #1
3
Input #2
2 3
2 4
Output #2
-1

Sign in to submit a solution

Signing up is free and takes a minute.