#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 0.0000000001;
const int N = 1000000 + 10;
struct node {
  int x, y;
} a[N];
node aa, bb;
queue<node> q;
map<int, int> mp, mp2;
int n, k;
int BFS() {
  map<int, int>::iterator it;
  int t = 0;
  while (q.empty() == 0) {
    aa = q.front();
    q.pop();
    if (aa.x == 0) {
      return aa.y;
    }
    t++;
    for (it = mp.begin(); it != mp.end(); it++) {
      bb.x = aa.x + it->first;
      bb.y = aa.y + 1;
      if (mp2[bb.x] == 1) continue;
      if (bb.x <= 1000 && bb.x >= -1000) {
        mp2[bb.x] = 1;
        q.push(bb);
      }
    }
  }
  return -1;
}
int main() {
  while (scanf("%d%d", &n, &k) != EOF) {
    if (n > 1000) {
      cout << -1 << endl;
      continue;
    }
    node aa;
    mp.clear();
    mp2.clear();
    while (q.empty() == 0) q.pop();
    for (int i = 1; i <= k; i++) {
      scanf("%d", &a[i].x);
      a[i].x = a[i].x - n;
      a[i].y = 1;
      if (mp[a[i].x] == 0) q.push(a[i]);
      mp[a[i].x] = 1;
      mp2[a[i].x] = 1;
    }
    cout << BFS() << endl;
  }
  return 0;
}
