#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, fl;
vector<long long> ar;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  a = 6;
  ar.resize(6);
  for (int i = 0; i < (int)a; ++i) cin >> ar[i];
  cin >> b;
  if (b == 1) {
    cout << 0;
    return 0;
  }
  long long ans = 1e18;
  vector<long long> pp(b);
  for (int i = 0; i < (int)b; ++i) {
    cin >> pp[i];
  }
  vector<pair<long long, long long> > gg;
  for (int i = 0; i < (int)a; ++i) {
    for (int j = 0; j < (int)b; ++j) {
      gg.push_back({pp[j] - ar[i], j});
    }
  }
  sort(gg.begin(), gg.end());
  map<long long, long long> map1;
  multiset<long long> set1;
  ans = 1e18;
  vector<vector<long long> > next(b);
  for (int i = 0; i < (int)gg.size(); ++i) {
    next[gg[i].second].push_back(i);
    if (next[gg[i].second].size() == 1) set1.insert(gg[i].first);
  }
  for (int i = 0; i < (int)b; ++i) reverse(next[i].begin(), next[i].end());
  for (int i = 0; i < (int)gg.size(); ++i) {
    ans = min(ans, abs(gg[i].first - *(--set1.end())));
    next[gg[i].second].pop_back();
    if (next[gg[i].second].size() == 0) break;
    set1.erase(set1.find(gg[i].first));
    set1.insert(gg[next[gg[i].second].back()].first);
  }
  cout << ans;
}
