#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int book[MAXN * 2];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int tmp;
    scanf("%d", &tmp);
    a[tmp] = 1;
  }
  queue<int> Q;
  memset(book, 0x3f, sizeof(book));
  for (int i = 0; i <= 1000; i++) {
    if (a[i]) {
      book[i - n + MAXN] = 1;
      Q.push(i - n + MAXN);
    }
  }
  while (!Q.empty()) {
    if (book[MAXN] != INF) {
      return 0 * printf("%d\n", book[MAXN]);
    }
    int now = Q.front();
    Q.pop();
    for (int i = 0; i <= 1000; i++) {
      if (!a[i]) continue;
      int co = i - n;
      int nxt = now + co;
      if (nxt < 0 || nxt > 2005) continue;
      if (book[nxt] > book[now] + 1) {
        Q.push(nxt);
        book[nxt] = book[now] + 1;
      }
    }
  }
  printf("-1\n");
  return 0;
}
