#include <bits/stdc++.h>
using namespace std;
struct node {
  int v, s;
};
queue<node> q;
int n, k, x, cnt, a[1010], vis[1010];
map<int, bool> mp;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &x);
    if (vis[x]) continue;
    vis[x] = 1, a[++cnt] = x;
  }
  for (int i = 1; i <= cnt; i++) a[i] -= n, q.push({a[i], 1}), mp[a[i]] = 1;
  while (!q.empty()) {
    node u = q.front();
    q.pop();
    if (u.v == 0) {
      printf("%d\n", u.s);
      return 0;
    }
    for (int i = 1; i <= cnt; i++) {
      if (mp[u.v + a[i]] || abs(u.v + a[i]) > 10000) continue;
      mp[u.v + a[i]] = 1, q.push({u.v + a[i], u.s + 1});
    }
  }
  puts("-1");
  return 0;
}
