import java.util.*; class Main { static int INF = 2 << 27; 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[n][c+1]; for(int i = 0; i < n; i++) { Arrays.fill(dp[i], INF); dp[i][0] = 0; } for(int i = 0; i < n; i++) { for(int j = 0; j <= c; j++) { if(i != 0) { dp[i][j] = Math.min(dp[i-1][j],dp[i][j]); } if(dp[i][j] == INF) { continue; } for(int k = 0; k <= c; k++) { if(j + a[i]*k > c) break; dp[i][j + a[i]*k] = Math.min((dp[i][j] + k),dp[i][j + a[i]*k]); } } } int min = INF; for(int i = 0; i < n; i++) { min = Math.min(dp[i][c], min); } if(min == INF) { min = -1; } System.out.println(min); } }