1879.The Great Mixing

Time Limit: 1s Memory Limit: 256MB

Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration 1879_1.png. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration 1879_2.png. The drink should also be tasty, so the glass can contain only integer number of liters of each Coke type (some types can be not presented in the glass). Also, they want to minimize the total volume of Coke in the glass.Carbon dioxide concentration is defined as the volume of carbone dioxide in the Coke divided by the total volume of Coke. When you mix two Cokes, the volume of carbon dioxide sums up, and the total volume of Coke sums up as well.Help them, find the minimal natural number of liters needed to create a glass with carbon dioxide concentration 1879_2.png. Assume that the friends have unlimited amount of each Coke type.

Input Format(From the terminal/stdin)

Input The first line contains two integers n, k (0 \le n \le 1000, 1 \le k \le 106)- carbon dioxide concentration the friends want and the number of Coke types.The second line contains k integers a1,a2,...,ak (0 \le ai \le 1000)- carbon dioxide concentration of each type of Coke. Some Coke types can have same concentration.

Output Format(To the terminal/stdout)

Output Print the minimal natural number of liter needed to prepare a glass with carbon dioxide concentration 1879_2.png, or -1 if it is impossible.

Sample Input 1

Copy
400 4
100 300 450 500
   · \n
   ·   ·   ·   \n

Sample Output 1

Copy
2
 \n

Sample Input 2

Copy
50 2
100 25
  · \n
   ·  \n

Sample Output 2

Copy
3
 \n

Hints

In the first sample case, we can achieve concentration 1879_3.png using one liter of Coke of types 1879_4.png and 1879_5.png: 1879_6.png.In the second case, we can achieve concentration 1879_7.png using two liters of 1879_8.png type and one liter of 1879_9.png type: 1879_10.png.

Submit

请先 登录

© 2025 FAQs