#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int tot, n, m;
int a[2020];
bool vis[2020];
struct node {
  int val, step;
} u, v;
queue<node> Q;
map<int, bool> used;
map<int, int> f;
int cnt = 0;
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int x = read();
    if (vis[x]) continue;
    vis[x] = 1;
    a[++tot] = x - n;
  }
  u.val = 0, u.step = 0;
  Q.push(u);
  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    if (used[u.val] && f[u.val] <= u.step) continue;
    if (u.step) used[u.val] = 1, f[u.val] = u.step;
    if (u.step && u.val == 0) {
      printf("%d\n", u.step);
      return 0;
    }
    for (int i = 1; i <= tot; i++) {
      int x = u.val + a[i];
      v.val = x, v.step = u.step + 1;
      if (v.val < 0 || v.val > 2000) continue;
      if (used[v.val] && f[v.val] <= v.step) continue;
      Q.push(v);
      cnt++;
    }
  }
  printf("-1\n");
}
