#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int NN = 1010100;
map<int, int> mp;
int a[NN], dp[NN];
queue<pii> q;
int main() {
  int p, n;
  cin >> p >> n;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  n = unique(a + 1, a + n + 1) - a - 1;
  for (int i = 1; i <= n; i++) a[i] -= p;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0) {
      puts("1");
      return 0;
    }
    q.push(pii(a[i], 1));
    mp[a[i]] = 1;
  }
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int u = p.first, w = p.second;
    for (int i = 1; i <= n; i++) {
      int v = u + a[i];
      if (v <= 1000 && v >= -1000) {
        if (!mp[v]) q.push(pii(v, w + 1));
        mp[v] = 1;
        if (v == 0) {
          cout << w + 1 << endl;
          return 0;
        }
      }
    }
  }
  puts("-1");
  return 0;
}
