#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int bp[252000];
int bm[252000];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  std::vector<int> cm(1001, 0);
  std::vector<int> cp(1001, 0);
  for (int i = 0; i < k; i++) {
    int x;
    scanf("%d", &x);
    x -= n;
    if (x == 0) {
      cout << 1;
      return 0;
    } else if (x > 0) {
      cp[x] = 1;
    } else {
      cm[-x] = 1;
    }
  }
  std::vector<int> p;
  std::vector<int> m;
  for (int i = 0; i < 1001; i++)
    if (cp[i]) p.push_back(i);
  for (int i = 0; i < 1001; i++)
    if (cm[i]) m.push_back(i);
  if (p.empty() || m.empty()) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < 252000; i++) {
    bp[i] = 10000;
    bm[i] = 10000;
  }
  bp[0] = 0;
  bm[0] = 0;
  int ans = 10000;
  for (int i = 0; i < 251000; i++) {
    if (i > 0) ans = min(ans, bp[i] + bm[i]);
    int bp1 = bp[i] + 1;
    int bm1 = bm[i] + 1;
    for (auto x : p) bp[x + i] = min(bp[x + i], bp1);
    for (auto x : m) bm[x + i] = min(bm[x + i], bm1);
  }
  cout << ans;
}
