Under construction

Still being built. Things may change

Golf

Interview

Time limit1sMemory limit1024 MB

Summary
Given a distance D and C club distances, find the fewest strokes that sum to exactly D, or 0 if impossible.
Level

Medium4 of 10

Topics
Dynamic programming, Array
Solved
No attempts yet

Problem

Like everyone else, the cows love the relaxation and challenge of a good game of golf. Bessie plays extraordinarily well and can aim her shot perfectly toward the hole, every time. Each club drives the ball exactly the distance specified for that club, every time.

Bessie is a smart cow. She knows she can overshoot and then hit back toward the hole, and she uses this to her advantage.

For those who do not play golf: every time the ball is hit, a stroke is counted. The object of golf is to hit the ball from the tee into the hole in as few strokes as possible. The lowest score wins.

Bessie needs a program to select the best combination of clubs to reach a given hole in the fewest strokes. If that is impossible, she wants to know, and she graciously accepts the loss. Cows are sturdier than humans, so Bessie can carry CC clubs (1≤C≤321 \le C \le 32), and the total distance DD from the tee to the hole does not exceed 10,000 yards (1≤D≤100001 \le D \le 10000).

Input

The first line has two space-separated integers, DD and CC. Each of the next CC lines contains a single integer RR (1≤R≤4001 \le R \le 400), the number of yards that club drives the ball. No two clubs share the same distance.

Output

Print a single line with the minimum number of strokes needed to move the ball from the tee to the hole. Print 0 if it is impossible to reach the hole with the given clubs.

Examples1

  1. Example 1

    Input
    100 3
    33
    66
    1
    
    Expected output
    3