#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <cstdio>
#include <cmath>
using namespace std;

typedef long long LL;
const LL inf = (LL)2e17;
const int maxn = 8;
typedef set<LL>::iterator it;

set<LL> f[ 1 << maxn ];
int m, n;
LL a[ maxn ];
inline LL ABS(LL x) {return x < 0 ? - x : x; }
int c[ 1 << maxn ], cid;

void gao(){
	//int t0 = clock();
	for(int i=0;i<(1<<n);++i) f[i].clear();
	for(int i=0;i<n;++i) f[1<<i].insert( a[i] );
	for(int i=1;i<(1<<n);++i){
		++ cid;
		for(int j=i;j;j=(j-1)&i) {
			int k=i^j;
			if(c[k] == cid) break;
			c[j]=cid;
			if(!k) continue;
			for(it p = f[j].begin(); p != f[j].end(); ++ p)
				for(it q = f[k].begin(); q != f[k].end(); ++ q) {
					LL t;
					t = (*p)+(*q);
					if(ABS(t) < inf) f[i].insert( t );
					t = (*p)-(*q);
					if(ABS(t) < inf ) f[i].insert( t );
					if(ABS(*p) < inf / (ABS(*q)+1)) {
						t=(*p)*(*q);
						f[i].insert( t );
					}
					if(ABS(*q)) {
						t=(*p)/(*q);
						f[i].insert( t );
					}
				}
		}
	}
	LL ans = 0;
	bool flg = 0;
	for(int i = 1; i < (1 << n); ++ i)
		for(it p = f[i].begin(); p != f[i].end(); ++ p) {
			if(!flg || ABS((*p)-m) < ABS(ans-m)) {
				flg = 1;
				ans = (*p);
			}
		}
	printf("%lld\n", ans);
	//cout <<"times = " << clock() - t0 << endl;
}

int main(){
	while(2 == scanf("%d%d", &m, &n), n || m) {
		for(int i=0;i<n;++i) scanf("%lld", a + i);
		gao();
	}
	return 0;
}
