#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
ll P=1e9+7;
ll a[200001];
ll maxi[200001];
ll mini[200001];
ll prefix[200001][6];
ll suffix[200001][6];
void solve(){
ll i,j,k,l,m,n,o,p,q,r,g,s,x,pos,d;
vector<ll> v(6);
for(i=0;i<6;i++){
cin>>v[i];
}
sort(v.begin(),v.end());
cin>>n;
for(j=0;j<6;j++){
prefix[0][j]=LLONG_MAX;
suffix[n+1][j]=0;
}
for(i=1;i<=n;i++){
cin>>a[i];
maxi[i]=0;
mini[i]=1e17;
}
sort(a+1,a+n+1);
for(i=1;i<=n;i++){
for(j=0;j<6;j++){
ll note=a[i]-v[j];
for(k=0;k<6;k++){
prefix[i][j]=min(prefix[i-1][k],note);
}
}
}
ll ans=LLONG_MAX;
for(i=n;i>=1;i--){
for(j=0;j<6;j++){
ll note=a[i]-v[j];
for(k=0;k<6;k++){
suffix[i][j]=max(suffix[i+1][k],note);
}
}
}
for(i=1;i<=n;i++){
for(j=0;j<6;j++){
ans=min(ans,suffix[i][j]-prefix[i][j]);
}
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgaW50IGxsOwojZGVmaW5lIGVuZGwgIlxuIgpsbCBQPTFlOSs3OwpsbCBhWzIwMDAwMV07CmxsIG1heGlbMjAwMDAxXTsKbGwgbWluaVsyMDAwMDFdOwpsbCBwcmVmaXhbMjAwMDAxXVs2XTsKbGwgc3VmZml4WzIwMDAwMV1bNl07CnZvaWQgc29sdmUoKXsKICAgIGxsIGksaixrLGwsbSxuLG8scCxxLHIsZyxzLHgscG9zLGQ7CiAgICB2ZWN0b3I8bGw+IHYoNik7CiAgICBmb3IoaT0wO2k8NjtpKyspewogICAgICAgIGNpbj4+dltpXTsKICAgIH0KICAgIHNvcnQodi5iZWdpbigpLHYuZW5kKCkpOwogICAgY2luPj5uOwogICAgZm9yKGo9MDtqPDY7aisrKXsKICAgICAgICBwcmVmaXhbMF1bal09TExPTkdfTUFYOwogICAgICAgIHN1ZmZpeFtuKzFdW2pdPTA7CiAgICB9CgogICAgZm9yKGk9MTtpPD1uO2krKyl7CiAgICAgICAgY2luPj5hW2ldOwogICAgICAgIG1heGlbaV09MDsKICAgICAgICBtaW5pW2ldPTFlMTc7CiAgICB9CiAgICBzb3J0KGErMSxhK24rMSk7CiAgICBmb3IoaT0xO2k8PW47aSsrKXsKICAgICAgICBmb3Ioaj0wO2o8NjtqKyspewogICAgICAgICAgICBsbCBub3RlPWFbaV0tdltqXTsKICAgICAgICAgICAgZm9yKGs9MDtrPDY7aysrKXsKICAgICAgICAgICAgICAgIHByZWZpeFtpXVtqXT1taW4ocHJlZml4W2ktMV1ba10sbm90ZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICAgICAgfQogICAgfQoKICAgIGxsIGFucz1MTE9OR19NQVg7CiAgICBmb3IoaT1uO2k+PTE7aS0tKXsKICAgICAgICBmb3Ioaj0wO2o8NjtqKyspewogICAgICAgICAgICAgbGwgbm90ZT1hW2ldLXZbal07CiAgICAgICAgICAgICBmb3Ioaz0wO2s8NjtrKyspewogICAgICAgICAgICAgICAgIHN1ZmZpeFtpXVtqXT1tYXgoc3VmZml4W2krMV1ba10sbm90ZSk7CiAgICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgZm9yKGk9MTtpPD1uO2krKyl7CiAgICAgICAgZm9yKGo9MDtqPDY7aisrKXsKICAgICAgICAgICAgYW5zPW1pbihhbnMsc3VmZml4W2ldW2pdLXByZWZpeFtpXVtqXSk7CiAgICAgICAgfQogICAgfQogICAgY291dDw8YW5zPDxlbmRsOwp9CmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKDApOwogICAgbGwgdD0xOwogICAgLy9jaW4+PnQ7CiAgICB3aGlsZSh0LS0pewogICAgICAgIHNvbHZlKCk7CiAgICB9CiAgICByZXR1cm4gMDsKfQo=