#include <cstdio>
#include <set>
#include <algorithm>
#include <cstdlib>
#define two(v) (1<<(v))
#define LL long long
using namespace std;

set <LL> st[128];
const LL oo = 2e17;
int T, N, a[10];

int main()
{
//    while (1)
    while (scanf("%d%d", &T, &N), N)
    {
//        T = rand(); N = 7;
        for (int i = 0; i < N; ++i) scanf("%d", &a[i]);
        //a[i] = rand();
        for (int i = 0; i < N; ++i) st[two(i)].insert(a[i]);
        LL ans = a[0];
        for (int i = 1; i < two(N); ++i)
        {
            for (int j = i&(i-1); j; j = (j-1)&i)
            {
                int k = i - j;
                for (set <LL> :: iterator l = st[j].begin(); l != st[j].end(); ++l)
                    for (set <LL> :: iterator r = st[k].begin(); r != st[k].end(); ++r)
                    {
                        LL t = (*l) + (*r);
                        if (abs(t) < oo) st[i].insert(t);
                        t = (*l) - (*r);
                        if (abs(t) < oo) st[i].insert(t);
                        if (!(*r) || oo / abs((*r)) > abs((*l))) st[i].insert((*l)*(*r));
                        if ((*r)) st[i].insert((*l)/(*r));
                    }
            }
            for (set <LL> :: iterator it = st[i].begin(); it != st[i].end(); ++it)
                if (abs((*it) - T) < abs(ans - T)) ans = *it;
            if (ans == T)
                break;
        }
        for (int i = 0; i < two(N); ++i) st[i].clear();
        printf("%d\n", (int)ans);
    }
    return 0;
}
