#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool f = false;
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - 48, ch = getchar();
  return f ? -x : x;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
int n, P, ANS[2005], L[2005], h = 0, t = 0;
int main() {
  P = read();
  n = read();
  for (int i = 1; i <= n; i++) ANS[read() - P + 1000] = 1;
  for (int i = 0; i <= 2000; i++)
    if (ANS[i]) L[++t] = i;
  while (h < t) {
    h++;
    for (int i = 0; i <= 2000; i++)
      if (1000 <= i + L[h] && 3000 >= i + L[h])
        if (ANS[i] == 1 && !ANS[i + L[h] - 1000])
          ANS[i + L[h] - 1000] = ANS[L[h]] + 1, L[++t] = i + L[h] - 1000;
  }
  if (!ANS[1000])
    printf("-1");
  else
    write(ANS[1000]);
  return 0;
}
