#include <bits/stdc++.h>   using namespace std;   void mf() { freopen( input.in ,  r , stdin); }   int a[1007];   int n, k;   map<int, int> mm;   queue<int> q;   bool f(map<int, int>& _mm, int x) { return _mm.find(x) != _mm.end(); }   void solve() {     int m;     n = 0;     cin >> k >> m;     int x;     for (int i = 1; i <= m; i++) {       cin >> x;       x -= k;       if (!f(mm, x)) {         mm[x] = 1;         n++;         a[n] = x;         q.push(x);       }     }     while (!f(mm, 0) && !q.empty()) {       x = q.front();       q.pop();       for (int i = 1; i <= n; i++) {         int nx = x + a[i];         if (nx > 1000 || nx < -1000) continue;         if (!f(mm, nx)) {           mm[nx] = mm[x] + 1;           q.push(nx);         }       }     }     if (f(mm, 0)) {       cout << mm[0];     } else {       cout << -1;     }   }   int main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }   