package main; import java.util.*; public class Main { public static final int INF = 1 << 29; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int c = sc.nextInt(); int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int[] dp = new int[c + 1]; Arrays.fill(dp, INF); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= c; j++) { if (j >= a[i]) { dp[j] = Math.min(dp[j], dp[j - a[i]] + 1); } } } System.out.println(dp[c] == INF ? -1 : dp[c]); } }