#include <bits/stdc++.h>
using namespace std;
int n, m, A[2100], num, d[2100], tail, p[2100];
bool v[2100];
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    x -= m;
    v[x + 1000] = 1;
  }
  for (int i = 0; i <= 2000; i++)
    if (v[i]) A[++num] = i - 1000, d[i] = 1, p[++tail] = i;
  for (int i = 1; i <= tail; i++) {
    int x = p[i];
    for (int j = 1; j <= num; j++) {
      int y = x + A[j];
      if (y < 0 || y > 2000 || v[y]) continue;
      d[y] = d[x] + 1;
      v[y] = 1;
      p[++tail] = y;
    }
    if (v[1000]) break;
  }
  if (v[1000] == 0)
    printf("-1\n");
  else
    printf("%d\n", d[1000]);
  return 0;
}
