#include <bits/stdc++.h>
using namespace std;
queue<pair<int, int> > q;
set<int> a;
bool visit[2004] = {0};
int main() {
  ios_base::sync_with_stdio(0);
  int n, i, j, k, ans = -1, flag1 = 0, flag2 = 0, x;
  cin >> n >> k;
  for (int(i) = (1); (i) <= (k); ++i) {
    cin >> x;
    a.insert(x - n);
    if (x - n >= 0) flag1 = 1;
    if (x - n <= 0) flag2 = 1;
  }
  if (!flag1 || !flag2) {
    cout << -1;
    return 0;
  }
  q.push({0, 0});
  while (!q.empty()) {
    int u = q.front().first;
    int v = q.front().second;
    q.pop();
    if (!u && v) {
      ans = v;
      break;
    }
    for (auto it = a.begin(); it != a.end(); it++) {
      if (abs(*it + u) < 1001 && !visit[*it + u + 1000]) {
        q.push({*it + u, v + 1});
        visit[*it + u + 1000] = 1;
      }
    }
  }
  cout << ans;
  return 0;
}
