#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 1e5 + 5;
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(k);
  queue<int> q;
  unordered_map<int, int> dist;
  unordered_set<int> s;
  unordered_map<int, bool> used;
  for (int i = 0; i < k; i++) {
    cin >> a[i];
    a[i] -= n;
    if (s.count(a[i]) == 0) {
      dist[a[i]] = 1;
      s.insert(a[i]);
      q.push(a[i]);
      used[a[i]] = 1;
    }
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    if (v == 0) {
      cout << dist[v] << '\n';
      return 0;
    }
    for (int x : s) {
      if (abs(x + v) < 1001 && !used[x + v]) {
        used[x + v] = 1;
        q.push(x + v);
        dist[v + x] = dist[v] + 1;
      }
    }
  }
  cout << "-1\n";
  return 0;
}
