#include <bits/stdc++.h>
using namespace std;
struct ff {
  int to, nxt;
} e[2005 * 2005];
int n, m, x, i, j, l, r, cnt, q[2005], dis[2005], vis[2005], head[2005];
void add(int u, int v) {
  e[++cnt] = (ff){v, head[u]};
  head[u] = cnt;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) scanf("%d", &x), vis[x] = 1;
  for (i = 0; i <= 1000; i++)
    if (vis[i])
      for (j = 0; j <= 2000; j++)
        if (j + i - n >= 0 && j + i - n <= 2000) add(j, j + i - n);
  memset(vis, 0, sizeof(vis));
  l = r = 1, q[1] = 1000;
  dis[1] = 0;
  while (l <= r) {
    for (i = head[q[l]]; i; i = e[i].nxt) {
      int v = e[i].to;
      if (vis[v]) continue;
      if (v == 1000) {
        printf("%d\n", dis[l] + 1);
        return 0;
      }
      vis[v] = 1, q[++r] = v;
      dis[r] = dis[l] + 1;
    }
    l++;
  }
  puts("-1");
  return 0;
}
