#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100010];
int tot[200010];
int dis[200010];
int main() {
  queue<int> q;
  scanf("%d%d", &n, &k);
  for (int i = 0; i <= 4000; ++i) dis[i] = 1e9;
  for (int i = 1; i <= k; ++i) {
    scanf("%d", &a[i]);
    a[i] -= n;
    ++tot[a[i] + 2000];
    if (dis[tot[a[i] + 2000]] == 1e9) q.push(a[i]);
    dis[a[i] + 2000] = 1;
  }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = -2000; i <= 2000; ++i) {
      if (dis[i + 2000] == 1 && dis[i + now + 2000] == 1e9) {
        dis[i + now + 2000] = dis[now + 2000] + 1;
        q.push(i + now);
      }
    }
  }
  if (dis[2000] == 1e9) dis[2000] = -1;
  printf("%d\n", dis[2000]);
}
