#include <bits/stdc++.h>
const int N = 10000;
using namespace std;
int n, k, i, x, a[1010], dist[200010];
bool ok[1010], in[200010];
deque<int> q;
int main() {
  cin >> n >> k;
  for (i = 1; i <= k; i++) {
    scanf("%d", &x);
    ok[x] = 1;
  }
  if (ok[n]) {
    cout << 1;
    return 0;
  }
  k = 0;
  for (i = 0; i <= 1000; i++)
    if (ok[i]) a[++k] = i - n;
  memset(dist, 127, sizeof(dist));
  for (i = 1; i <= k; i++) {
    q.push_back(a[i] + N);
    in[a[i] + N] = 1;
    dist[a[i] + N] = 1;
  }
  while (q.size()) {
    auto it = q.front();
    q.pop_front();
    in[it] = 0;
    if (it == N) {
      cout << dist[it];
      return 0;
    }
    for (i = 1; i <= k; i++)
      if ((it + a[i] <= N + 2000) && (it + a[i] >= N - 2000))
        if (dist[it + a[i]] > dist[it] + 1) {
          dist[it + a[i]] = dist[it] + 1;
          if (!in[it + a[i]]) q.push_back(it + a[i]);
          in[it + a[i]] = 1;
        }
  }
  cout << -1;
  return 0;
}
