import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int m = sc.nextInt(); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } Arrays.sort(arr); int[] dp = new int[m + 1]; for (int i = 1; arr[0] * i <= m; i++) { dp[arr[0] * i] = i; } for (int i = 1; i < n; i++) { for (int j = 0; j + arr[i] <= m; j++) { if (j != 0 && dp[j] == 0) { continue; } for (int k = 1; j + arr[i] * k <= m; k++) { dp[j + arr[i] * k] = Math.max(dp[j + arr[i] * k], dp[j] + k); } } } long ans = 0; for (int i = 0; i <= m; i++) { ans = Math.max(ans, dp[i]); } boolean[] isNotPrime = new boolean[m + 1]; for (int i = 2; i < m; i++) { if (!isNotPrime[i]) { ans += dp[m - i]; for (int j = 2; i * j <= m; j++) { isNotPrime[i * j] = true; } } } System.out.println(ans); } }