#include <bits/stdc++.h>
using namespace std;
inline void in(int& x) {
  char c;
  while (c = getchar(), c <= ' ')
    ;
  bool sign(c == '-');
  if (sign) c = getchar();
  x = (c - '0');
  while (c = getchar(), !(c<'0' | c> '9')) x = 10 * x + c - '0';
  if (sign) x = -x;
}
const int N = 2001;
int a[N], c[N];
int main() {
  int n, k;
  in(n), in(k);
  queue<pair<int, int>> q;
  for (int i = 0, j; i < k; i++) {
    in(j);
    if (!c[j + 1000 - n]) {
      c[j + 1000 - n] = 1;
      a[j + 1000 - n] = 1;
      q.push({j + 1000 - n, 1});
    }
  }
  while (!q.empty()) {
    int u = q.front().first, d = q.front().second;
    q.pop();
    if (u == 1000) {
      cout << d << endl;
      return 0;
    }
    for (int i = 0, j; i < N; i++)
      if (c[i]) {
        j = u + i - 1000;
        if (0 <= j && j < N && !a[j]) {
          a[j] = 1;
          q.push({j, d + 1});
        }
      }
  }
  puts("-1");
  return 0;
}
