#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
using namespace std;
int n, k, a[1005], d[100005], q[100005], dem;
void setup() {
  read(n);
  read(k);
  while (k--) {
    int x;
    read(x);
    a[x] = 1;
  }
}
void work() {
  for (int i = (0); i <= (100000); i++) d[i] = 1000000007;
  for (int i = (0); i <= (1000); i++)
    if (a[i]) {
      int v = i + 10000 - n;
      d[v] = 1;
      q[++dem] = v;
    }
  for (int i = (1); i <= (dem); i++) {
    int v = q[i];
    for (int j = (0); j <= (1000); j++)
      if (a[j]) {
        int u = v + j - n;
        if (u < 0 || u >= 11000) continue;
        if (d[u] > d[v] + 1) {
          d[u] = d[v] + 1;
          q[++dem] = u;
        }
      }
  }
  if (d[10000] != 1000000007)
    write(d[10000]);
  else
    write(-1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  setup();
  work();
  return 0;
}
