using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; class Template { static Scanner sc; public static void Main(string[] args) { const int INF = (int)1e9; sc = new Scanner(); int C = sc.nextInt(); int N = sc.nextInt(); int[] a = sc.nextIntArray(); Array.Sort(a); Array.Reverse(a); int[] dp = new int[C * 2]; for (int i = 0; i < dp.Length; i++) { dp[i] = INF; } //dp[i] : f(...) = iになるxの和の最小値 dp[0] = 0; //while (true) { for (int i = 0; i < C; i++) { foreach (var el in a) { if (i + el <= C && dp[i] != INF) { dp[i + el] = Math.Min(dp[i + el], dp[i] + 1); } } } } if (dp[C] == INF) { dp[C] = -1; } Console.WriteLine(dp[C]); } } public class Scanner { public Scanner() { } public string next() { return Console.ReadLine(); } public int nextInt() { return int.Parse(next()); } public double nextDouble() { return double.Parse(next()); } public long nextLong() { return long.Parse(next()); } public string[] nextArray() { return next().Split(' '); } public int[] nextIntArray() { return Array.ConvertAll(nextArray(), e => int.Parse(e)); } public long[] nextLongArray() { return Array.ConvertAll(nextArray(), e => long.Parse(e)); } public double[] nextDoubleArray() { return Array.ConvertAll(nextArray(), e => double.Parse(e)); } }