#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int N, K;
bool appeared[1003];
vector<int> num1, num2;
int ju1[250333];
int ju2[250333];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  scanf("%d%d", &N, &K);
  for (int zz = 0; zz < (K); zz++) {
    int a;
    scanf("%d", &a);
    if (appeared[a]) continue;
    appeared[a] = true;
    a -= N;
    if (a == 0) {
      puts("1");
      exit(0);
    } else if (a > 0)
      num1.push_back(a);
    else
      num2.push_back(-a);
  }
  if (num1.empty() || num2.empty()) {
    puts("-1");
    exit(0);
  }
  const int A1 = *max_element(num1.begin(), num1.end());
  const int A2 = *max_element(num2.begin(), num2.end());
  int lcm = A1 * A2 / gcd(A1, A2);
  int ans = (A1 + A2) / gcd(A1, A2);
  for (int d = 1; d < lcm; d++) {
    ju1[d] = 123456;
    for (int n : num1)
      if (d - n >= 0) ju1[d] = min(ju1[d], 1 + ju1[d - n]);
    ju2[d] = 123456;
    for (int n : num2)
      if (d - n >= 0) ju2[d] = min(ju2[d], 1 + ju2[d - n]);
    ans = min(ans, ju1[d] + ju2[d]);
  }
  printf("%d\n", ans);
  return 0;
}
