/*
 * 4.cpp
 *
 *  Created on: Apr 28, 2010
 *      Author: Justin Li
 */
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <queue>
#include <stack>
#include <fstream>
using namespace std;

int main() {
	ifstream in;
	in.open("DATA4.txt");
	ofstream out;
	out.open("OUT4.txt");
	int change, n, a, x, y;
	int arr[600], coins[100];
	for (int i=0; i<5; i++) {
		in>>change;
		in>>n;
		for (x=1;x<=n;x++)
			in>>coins[x];
		arr[0]=0;
		for (x=1;x<=change;x++) {
			a=1234567;
			for (y=1;y<=n;y++)
				if (x-coins[y]>=0)
					if (arr[x-coins[y]]!=-1&&arr[x-coins[y]]<a)
						a=arr[x-coins[y]]+1;
			if (a==1234567) arr[x]=-1;
			else arr[x]=a;
		}
		out<<arr[change]<<endl;
	}
	in.close();
	out.close();
	return 0;
}

