#include <bits/stdc++.h>
using namespace std;
int a[1000002], n, k, freq[2003], b[1000], ct = 0, m = 0, ans = 1e9, d[2003],
                                           dp[2003];
queue<int> q;
int bfs(int src) {
  for (int i = 0; i < 2003; ++i) {
    freq[i] = 0;
  }
  for (int i = 0; i < m; ++i) {
    q.push(b[i]);
    d[1000 + b[i]] = 1;
    freq[1000 + b[i]] = 1;
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < m; ++i) {
      if (u == 0) {
        return d[1000 + u];
      }
      if (freq[1000 + u + b[i]] == 1) {
        continue;
      }
      if ((u > 0 && b[i] < 0) || (u < 0 && b[i] > 0)) {
        d[1000 + u + b[i]] = d[1000 + u] + 1;
        freq[1000 + u + b[i]] = 1;
        q.push(u + b[i]);
      }
    }
  }
  return 1e9;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    scanf("%d", &a[i]);
    freq[a[i]]++;
    if (freq[a[i]] == 1) {
      b[m++] = a[i] - n;
    }
  }
  sort(b, b + m);
  ans = bfs(0);
  if (ans < 1e9) {
    cout << ans;
  } else {
    cout << -1;
  }
  return 0;
}
