#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int inf = 0x3f3f3f3f;
const int maxn = 1000005;
const int N = 105;
inline void read(int &x) {
  int f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  x *= f;
}
int n, k, a[maxn];
map<int, int> mp;
int bfs() {
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < k; i++) {
      int u = a[i] + x;
      if (abs(u) > 1000) continue;
      if (!mp[u]) {
        mp[u] = mp[x] + 1;
        q.push(u);
      }
      if (u == 0) return mp[u];
    }
  }
  return -1;
}
int main() {
  read(n), read(k);
  for (int i = 0; i < k; i++) {
    read(a[i]);
    a[i] -= n;
  }
  sort(a, a + k);
  k = unique(a, a + k) - a;
  cout << bfs() << endl;
  return 0;
}
