#include <bits/stdc++.h>
using namespace std;
int a[1000005];
map<int, int> vis;
struct node {
  int step, val;
};
queue<node> que;
int main() {
  int n, m;
  std::ios::sync_with_stdio(false);
  while (cin >> n >> m) {
    for (int i = 0; i < m; i++) {
      cin >> a[i];
      a[i] -= n;
    }
    sort(a, a + m);
    int cnt = unique(a, a + m) - a;
    node q;
    q.val = 0;
    q.step = 0;
    que.push(q);
    int flag;
    while (que.size()) {
      node p = que.front();
      que.pop();
      flag = 0;
      for (int i = 0; i < cnt; i++) {
        if (abs(p.val + a[i]) > 1001) continue;
        if (p.val + a[i] == 0) {
          cout << p.step + 1 << endl;
          flag = 1;
          break;
        }
        if (!vis[p.val + a[i]]) {
          q.val = p.val + a[i];
          q.step = p.step + 1;
          que.push(q);
          vis[p.val + a[i]] = 1;
        }
      }
      if (flag == 1) break;
    }
    if (flag == 0) cout << "-1" << endl;
  }
  return 0;
}
