#include <bits/stdc++.h>
using namespace std;
int dp_pos[1000010], dp_neg[1000010];
int mark_pos[1000010], mark_neg[1000010];
int pos[1000010], neg[1000010], cnt_pos = 0, cnt_neg = 0;
int max_pos, max_neg;
int a[1000010];
void calc(int* dp, int* mark) {
  int cnt = 0, i, j;
  for (i = 0; i <= max_pos * max_neg; i++) dp[i] = 10000000;
  for (i = 0; i <= 1000; i++)
    if (mark[i]) a[cnt++] = i;
  for (i = 0; i < cnt; i++) dp[a[i]] = 1;
  for (i = 1; i <= max_pos * max_neg; i++)
    for (j = 0; j < cnt && a[j] <= i; j++) dp[i] = min(dp[i], 1 + dp[i - a[j]]);
}
int main() {
  int n, k, i;
  scanf("%d", &n);
  scanf("%d", &k);
  memset(mark_pos, 0, sizeof(mark_pos));
  memset(mark_neg, 0, sizeof(mark_neg));
  for (i = 0; i < k; i++) {
    int x;
    scanf("%d", &x);
    if (x >= n)
      mark_pos[x - n] = 1;
    else
      mark_neg[n - x] = 1;
  }
  if (mark_pos[0]) {
    printf("1\n");
    return 0;
  }
  max_pos = max_neg = -10000000;
  for (i = 0; i <= 1000; i++)
    if (mark_pos[i]) max_pos = i;
  for (i = 0; i <= 1000; i++)
    if (mark_neg[i]) max_neg = i;
  if (max_neg == -10000000 || max_pos == -10000000) {
    printf("-1\n");
    return 0;
  }
  calc(dp_pos, mark_pos);
  calc(dp_neg, mark_neg);
  int ans = 2 * 10000000;
  for (i = 1; i <= max_neg * max_pos; i++)
    ans = min(ans, dp_pos[i] + dp_neg[i]);
  printf("%d\n", ans);
}
