#include <bits/stdc++.h>
using namespace std;
int n, k;
map<int, int> vis;
queue<pair<int, int> > que;
set<int> vec;
int solve() {
  while (que.size()) {
    pair<int, int> cur = que.front();
    que.pop();
    int val = cur.first, times = cur.second;
    if (val == 0) return times;
    for (auto o : vec) {
      int fval = val + o;
      if (fval >= -1000 && fval <= 1000 && vis[fval] == 0) {
        que.push({fval, times + 1});
        vis[fval] = 1;
      }
    }
  }
  return -1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; i++) {
    int x;
    scanf("%d", &x);
    x -= n;
    vec.insert(x);
    que.push({x, 1});
    vis[x] = 1;
  }
  printf("%d\n", solve());
  return 0;
}
