#include <bits/stdc++.h>
using namespace std;
int const N = 1010;
int const M = 1000100;
int f1[M], f2[M];
bool va[N], vb[N];
int a[N], b[N];
int ca, cb;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  bool flag = 0;
  for (int i = 1; i <= (k); ++i) {
    int x;
    scanf("%d", &x);
    x -= n;
    if (x < 0) {
      if (!vb[-x]) {
        vb[-x] = 1;
        b[cb++] = -x;
      }
    } else {
      if (!va[x]) {
        va[x] = 1;
        a[ca++] = x;
      }
    }
    if (x == 0) flag = 1;
  }
  if (flag) {
    puts("1");
    return 0;
  }
  memset(f1, (0x3f), sizeof f1), memset(f2, (0x3f), sizeof f2);
  f1[0] = f2[0] = 0;
  int ans = 0x3f3f3f3f;
  for (int i = 0; i < (M); ++i) {
    if (f1[i] != 0x3f3f3f3f && f2[i] != 0x3f3f3f3f) {
      if (f1[i] + f2[i] >= ans) {
        continue;
      }
    }
    if (f1[i] != 0x3f3f3f3f) {
      if (f1[i] >= ans) continue;
      for (int j = 0; j < (ca); ++j)
        if (i + a[j] < M) {
          f1[i + a[j]] = min(f1[i + a[j]], f1[i] + 1);
        }
    }
    if (f2[i] != 0x3f3f3f3f) {
      if (f2[i] >= ans) continue;
      for (int j = 0; j < (cb); ++j)
        if (i + b[j] < M) {
          f2[i + b[j]] = min(f2[i + b[j]], f2[i] + 1);
        }
    }
    if (i > 0 && f1[i] != 0x3f3f3f3f && f2[i] != 0x3f3f3f3f) {
      ans = min(ans, f1[i] + f2[i]);
    }
  }
  if (ans == 0x3f3f3f3f)
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}
