Minimum number of numbers to sum to exactly n First question here, don't yell at me if this is a duplicate or a bad challenge.

Introduction

I thought of this challenge myself, and it seems to be a good basic puzzle for beginner code-golfers. It also might help me decide which code-golfing language to learn.

Challenge

Given an array of integers that are less than or equal to n, output or return the minimum number of numbers from the array that sum up to exactly n.

You can choose to write a function or a full program.

Input

You can safely assume 0 &lt;= n &lt; 2^31.

Take an array or list of any kind (vector for C++ or Java's LinkedList are allowed), along with n and an optional parameter length, which specifies the length of the array.

You can also take the input as a space-separated string, separated from n by either a comma or a space:

1 5 7 3 7 3 6 3 2 6 3,10

1 5 7 3 7 3 6 3 2 6 3 10


if it is easier.

Output

Output, or return the minimum number of numbers from the array that sum up to exactly n. Using the above example:

1 5 7 3 7 3 6 3 2 6 3,10


Your program should print:

2


because the minimum number of numbers that sum up to 10 is 2 (7 and 3).

In the case that there is no solution, print or return either a negative, 0, "No solution" (though that would not be smart), ∞ (as suggested), or any other falsy value, with the exception of an empty string.

Example Input and Output

Input:

1 5 7 3 7 3 6 3 2 6 3,10
143 1623 1646 16336 1624 983 122,18102
5 6 9,12


Output:

2
3
-1


Scoring

This is code-golf, so shortest code in bytes wins.

The top answer will be accepted on Christmas.
Pyth, 12 11 bytes
lhafqsTQyEY

This takes n as the first line of input and the list on the second line.
lhafqsTQyEY     (Implicit: Q = 1st line of input; E = 2nd line)
         E      The list
        yE      Powerset (sorted by increasing length; empty set first)
   f            Filter by lambda T:
     sT         sum(T)
    q                  ==
       Q                  Q
   fqSTQyE      Sublists that sum to Q, sorted by increasing length
  a       Y     append an empty array (in case none match)
lh              take the length of the first element (0 for empty array)

Try it here.