#include <bits/stdc++.h>
using namespace std;
int n, k, a, q[1000101], l, r, dis[2111];
bool inq[2001];
int main() {
  memset(dis, 0x7f, sizeof(dis));
  scanf("%d%d", &n, &k);
  l = 1;
  for (int i = 1; i <= k; i++) {
    scanf("%d", &a);
    if (a == n) {
      printf("1");
      return 0;
    }
    int tmp = a - n + 1000;
    dis[tmp] = 1;
  }
  for (int i = 0; i <= 2000; i++) {
    if (dis[i] == 1) {
      r++;
      q[r] = i;
    }
  }
  while (l <= r) {
    int u = q[l];
    l++;
    for (int i = 1; i <= 2000; i++) {
      if (dis[i] == 1 && dis[u + i - 1000] > 1e9) {
        r++;
        dis[u + i - 1000] = dis[u] + 1;
        q[r] = u + i - 1000;
      }
    }
  }
  if (dis[1000] > 1e9) {
    printf("-1");
    return 0;
  }
  printf("%d", dis[1000]);
}
