#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N,M;
ll a[105],weight[15];
map<ll,bool> MAP,PRE,CURRENT;
vector<ll> V,CAN_NOT;

void recursive(int index,ll add_sum){

	if(index == M){

		MAP[add_sum] = true;
		V.push_back(add_sum);

		return;
	}

	//足さない
	recursive(index+1,add_sum);

	//+(-weight[index])
	recursive(index+1,add_sum-weight[index]);

	//+weight[index]
	recursive(index+1,add_sum+weight[index]);
}

void func(){

	MAP.clear();
	V.clear();
	CAN_NOT.clear();
	PRE.clear();
	CURRENT.clear();

	for(int i = 0; i < N; i++){

		scanf("%lld",&a[i]);
	}

	for(int i = 0; i < M; i++){

		scanf("%lld",&weight[i]);
	}

	recursive(0,0);

	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());

	bool FLG = true;

	for(int i = 0; i < N; i++){

		auto at = MAP.find(a[i]);

		if(at == MAP.end()){
			FLG = false;
			CAN_NOT.push_back(a[i]);
		}
	}

	if(FLG){
		printf("0\n");
		return;
	}

	ll ans = HUGE_NUM;

	for(int i = 0; i < V.size(); i++){

		PRE[abs(CAN_NOT[0]-V[i])] = true;
		if(CAN_NOT.size() == 1){ //コーナーケース

			ans = min(ans,abs(CAN_NOT[0]-V[i]));
		}
	}

	for(int i = 1; i < CAN_NOT.size(); i++){

		for(int k = 0; k < V.size(); k++){

			auto at = PRE.find(abs(CAN_NOT[i]-V[k]));

			if(at != PRE.end()){

				CURRENT[abs(CAN_NOT[i]-V[k])] = true;

				if(i == CAN_NOT.size()-1){

					ans = min(ans,abs(CAN_NOT[i]-V[k]));
				}
			}
		}

		PRE.clear();
		PRE = CURRENT;
		CURRENT.clear();
	}

	if(ans == HUGE_NUM){

		printf("-1\n");
	}else{

		printf("%lld\n",ans);
	}
}

int main(){

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}

