#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - 48;
  return x * f;
}
int d[2100], n, m, x, a[2100];
bool vis[2100];
queue<int> q;
int main() {
  n = read();
  m = read();
  for (int i = 0; i < m; i++) {
    x = read();
    if (!vis[x]) a[++a[0]] = x, vis[x] = 1;
  }
  memset(d, -1, sizeof(d));
  q.push(1000);
  d[1000] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 1; i <= a[0]; i++) {
      int to = x + a[i] - n;
      if (to == 1000)
        return 0 * printf("%d\n", d[x] + 1);
      else if (to >= 0 && to <= 2010 && d[to] == -1)
        d[to] = d[x] + 1, q.push(to);
    }
  }
  puts("-1");
  return 0;
}
