#include <bits/stdc++.h>
using namespace std;
int n, k;
bool vis[1050];
int a[1050000];
int b[1050000];
int da[1050];
int db[1050];
int tota;
int totb;
struct edge {
  int step;
  int ed;
};
int main() {
  scanf("%d%d", &n, &k);
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= k; i++) {
    int tmp;
    scanf("%d", &tmp);
    vis[tmp] = true;
  }
  if (vis[n]) return 0 * printf("1\n");
  tota = totb = 0;
  bool flag = false;
  for (int i = 0; i < n; i++)
    if (vis[i]) {
      da[++tota] = n - i;
      flag = true;
    }
  if (!flag) return 0 * printf("-1\n");
  flag = false;
  for (int i = n + 1; i <= 1000; i++)
    if (vis[i]) {
      db[++totb] = i - n;
      flag = true;
    }
  if (!flag) return 0 * printf("-1\n");
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  queue<edge> que;
  que.push((edge){0, 0});
  while (!que.empty()) {
    edge tmp = que.front();
    que.pop();
    if (tmp.ed > 1000000 || a[tmp.ed]) continue;
    a[tmp.ed] = tmp.step;
    for (int i = 1; i <= tota; i++) {
      if (tmp.ed + da[i] <= 1000000 && !a[tmp.ed + da[i]])
        que.push((edge){tmp.step + 1, tmp.ed + da[i]});
    }
  }
  que.push((edge){0, 0});
  while (!que.empty()) {
    edge tmp = que.front();
    que.pop();
    if (tmp.ed > 1000000 || b[tmp.ed]) continue;
    b[tmp.ed] = tmp.step;
    for (int i = 1; i <= totb; i++) {
      if (tmp.ed + db[i] <= 1000000 && !b[tmp.ed + db[i]])
        que.push((edge){tmp.step + 1, tmp.ed + db[i]});
    }
  }
  int ans = 10000;
  for (int i = 1; i <= 1000000; i++) {
    if (!a[i] || !b[i]) continue;
    ans = min(ans, a[i] + b[i]);
  }
  printf("%d\n", ans);
}
