#include <bits/stdc++.h>
using namespace std;
int n, k;
const int n_ = 1000001;
int arr[n_];
int dist[2 * n_];
int inf = 1e7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> k >> n;
  queue<int> q;
  int off = 1000;
  for (int i = 0; i <= (int)2001; i++) dist[i] = inf;
  set<int> st;
  vector<int> v;
  for (int i = 0; i <= (int)n - 1; i++) {
    cin >> arr[i], arr[i] -= k, dist[arr[i] + off] = 1;
    if (!st.count(arr[i])) {
      st.insert(arr[i]);
      v.push_back(arr[i]);
      q.push(arr[i]);
    }
  }
  if (dist[off] == 1) {
    cout << "1\n";
    return 0;
  }
  while (!q.empty()) {
    int sum = q.front();
    q.pop();
    for (int i = 0; i <= (int)(int)v.size() - 1; i++)
      if (abs(sum + v[i]) <= 1000) {
        if (sum + v[i] == 0) {
          cout << dist[sum + off] + 1 << "\n";
          return 0;
        }
        if (dist[sum + v[i] + off] > dist[sum + off] + 1) {
          dist[off + sum + v[i]] = dist[off + sum] + 1;
          q.push(sum + v[i]);
        }
      }
  }
  cout << "-1\n";
  return 0;
}
