import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int C = sc.nextInt(); final int N = sc.nextInt(); int[] arr = new int[N]; for(int i = 0; i < N; i++){ arr[i] = sc.nextInt(); } int[] DP = new int[C + 1]; Arrays.fill(DP, -1); DP[0] = 0; for(final int a : arr){ for(int i = 0; i + a <= C; i++){ if(DP[i] < 0){ continue; } if(DP[i + a] < 0 || (DP[i] + 1 < DP[i + a])){ DP[i + a] = DP[i] + 1; } } } System.out.println(DP[C]); } }