#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int a[8];
cin >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6];
int n;
cin >> n;
vector<int>v(n + 3), val;
set<int>st;
map<int, vector<int> >mp;
for(int i = 1; i <= n; i++){
cin >> v[i];
for(int j = 1; j <= 6; j++){
if(st.find(v[i] - a[j]) == st.end()){
val.push_back(v[i] - a[j]);
st.insert(v[i] - a[j]);
}
mp[v[i] - a[j]].push_back(i);
}
}
vector<int>cnt(n + 5, 0);
int ans = 1e9 + 50;
sort(val.begin(), val.end());
int j = -1, c = 0;
for(int i = 0; i < val.size(); i++){
if(c == n){
ans = min(ans, val[j] - val[i]);
for(int r = 0; r < mp[val[i]].size(); r++){
int p = mp[val[i]][r];
cnt[p]--;
if(cnt[p] == 0){
c--;
}
}
continue;
}
for(int k = j + 1; k < val.size(); k++){
for(int r = 0; r < mp[val[k]].size(); r++){
int p = mp[val[k]][r];
cnt[p]++;
if(cnt[p] == 1){
c++;
}
}
if(c == n){
ans = min(ans, val[k] - val[i]);
j = k;
break;
}
if(k == n){
j = n + 1;
}
}
if(j == n + 1){
break;
}
for(int r = 0; r < mp[val[i]].size(); r++){
int p = mp[val[i]][r];
cnt[p]--;
if(cnt[p] == 0){
c--;
}
}
}
cout << ans;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IG1haW4oKXsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZSgwKTsKICAgIGludCBhWzhdOwogICAgY2luID4+IGFbMV0gPj4gYVsyXSA+PiBhWzNdID4+IGFbNF0gPj4gYVs1XSA+PiBhWzZdOwogICAgaW50IG47CiAgICBjaW4gPj4gbjsKICAgIHZlY3RvcjxpbnQ+dihuICsgMyksIHZhbDsKICAgIHNldDxpbnQ+c3Q7CiAgICBtYXA8aW50LCB2ZWN0b3I8aW50PiA+bXA7CiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKyl7CiAgICAgICAgY2luID4+IHZbaV07CiAgICAgICAgZm9yKGludCBqID0gMTsgaiA8PSA2OyBqKyspewogICAgICAgICAgICBpZihzdC5maW5kKHZbaV0gLSBhW2pdKSA9PSBzdC5lbmQoKSl7CiAgICAgICAgICAgICAgICB2YWwucHVzaF9iYWNrKHZbaV0gLSBhW2pdKTsKICAgICAgICAgICAgICAgIHN0Lmluc2VydCh2W2ldIC0gYVtqXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbXBbdltpXSAtIGFbal1dLnB1c2hfYmFjayhpKTsKICAgICAgICB9CiAgICB9CiAgICB2ZWN0b3I8aW50PmNudChuICsgNSwgMCk7CiAgICBpbnQgYW5zID0gMWU5ICsgNTA7CiAgICBzb3J0KHZhbC5iZWdpbigpLCB2YWwuZW5kKCkpOwogICAgaW50IGogPSAtMSwgYyA9IDA7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgdmFsLnNpemUoKTsgaSsrKXsKICAgICAgICBpZihjID09IG4pewogICAgICAgICAgICBhbnMgPSBtaW4oYW5zLCB2YWxbal0gLSB2YWxbaV0pOwogICAgICAgICAgICBmb3IoaW50IHIgPSAwOyByIDwgbXBbdmFsW2ldXS5zaXplKCk7IHIrKyl7CiAgICAgICAgICAgICAgICBpbnQgcCA9IG1wW3ZhbFtpXV1bcl07CiAgICAgICAgICAgICAgICBjbnRbcF0tLTsKICAgICAgICAgICAgICAgIGlmKGNudFtwXSA9PSAwKXsKICAgICAgICAgICAgICAgICAgICBjLS07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgayA9IGogKyAxOyBrIDwgdmFsLnNpemUoKTsgaysrKXsKICAgICAgICAgICAgZm9yKGludCByID0gMDsgciA8IG1wW3ZhbFtrXV0uc2l6ZSgpOyByKyspewogICAgICAgICAgICAgICAgaW50IHAgPSBtcFt2YWxba11dW3JdOwogICAgICAgICAgICAgICAgY250W3BdKys7CiAgICAgICAgICAgICAgICBpZihjbnRbcF0gPT0gMSl7CiAgICAgICAgICAgICAgICAgICAgYysrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKGMgPT0gbil7CiAgICAgICAgICAgICAgICBhbnMgPSBtaW4oYW5zLCB2YWxba10gLSB2YWxbaV0pOwogICAgICAgICAgICAgICAgaiA9IGs7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZihrID09IG4pewogICAgICAgICAgICAgICAgaiA9IG4gKyAxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmKGogPT0gbiArIDEpewogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZm9yKGludCByID0gMDsgciA8IG1wW3ZhbFtpXV0uc2l6ZSgpOyByKyspewogICAgICAgICAgICBpbnQgcCA9IG1wW3ZhbFtpXV1bcl07CiAgICAgICAgICAgIGNudFtwXS0tOwogICAgICAgICAgICBpZihjbnRbcF0gPT0gMCl7CiAgICAgICAgICAgICAgICBjLS07CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IGFuczsKICAgIHJldHVybiAwOwp9