import java.util.Arrays; import java.util.Scanner; public class Yukicoder247 { int now; static boolean ok = false; static int res = -1; static int[] a; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int c = sc.nextInt(); int n = sc.nextInt(); a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } Arrays.sort(a); // ゴリ押し gorigori(n - 1, c, 0); System.out.println(res); } public static void gorigori(int now, int nokori, int num) { if (ok || now < 0) return; if (nokori % a[now] == 0) { res = num + nokori / a[now]; ok = true; return; } for (int i = nokori / a[now]; i >= 0; i--) { gorigori(now - 1, nokori - i * a[now], num + i); } } }