using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static void Main() { new Magatro().Solve(); } } class Magatro { private int C; private int N; private int[] A; private void Scan() { C = int.Parse(Console.ReadLine()); N = int.Parse(Console.ReadLine()); A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public void Solve() { Scan(); var cost = (new int[C + 1]).Select(i => int.MaxValue).ToArray(); cost[0] = 0; for (int i = 0; i <= C; i++) { if (cost[i] == int.MaxValue) continue; foreach (int j in A) { if (i + j <= C) { cost[i + j] = Math.Min(cost[i + j], cost[i] + 1); } } } Console.WriteLine(cost[C] == int.MaxValue ? -1 : cost[C]); } }