#include <bits/stdc++.h>
using namespace std;
bool visited[2000 + 2];
vector<int> edges;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  int a;
  queue<pair<int, int> > q;
  map<int, int> h;
  for (int i = 0; i < k; i++) {
    cin >> a;
    if (h[a - n] == 0) {
      edges.push_back(a - n);
      h[a - n] = 1;
    }
    q.push(make_pair(a - n, 1));
    visited[a - n + 1000] = 1;
  }
  while (!q.empty()) {
    pair<int, int> temp = q.front();
    q.pop();
    if (temp.first == 0) {
      cout << temp.second << '\n';
      return 0;
    }
    for (auto it = edges.begin(); it != edges.end(); it++) {
      if ((*it) + temp.first <= 1000 && (*it) + temp.first >= -1 * 1000) {
        if (!visited[(*it) + temp.first + 1000]) {
          visited[(*it) + temp.first + 1000] = 1;
          q.push(make_pair((*it) + temp.first, temp.second + 1));
        }
      }
    }
  }
  cout << -1 << '\n';
  return 0;
}
