#include <bits/stdc++.h>
using namespace std;
template <class T, class V>
ostream &operator<<(ostream &s, pair<T, V> a) {
  s << a.first << ' ' << a.second;
  return s;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  for (int qq = 1; qq <= T; qq++) {
    vector<long long int> a(6);
    for (auto &x : a) cin >> x;
    int n;
    cin >> n;
    vector<pair<long long int, long long int> > all(6 * n);
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      for (int j = 0; j < 6; j++) all[i * 6 + j] = {x - a[j], i};
    }
    vector<long long int> cnt(n);
    int l = 0, r = 0, d = 0;
    sort(all.begin(), all.end());
    long long int ans = 2000000000;
    while (1) {
      while (d < n && r < 6 * n)
        cnt[all[r].second]++, d += (cnt[all[r++].second] == 1 ? 1 : 0);
      if (d != n) break;
      ans = min(ans, all[r - 1].first - all[l].first);
      cnt[all[l].second]--;
      if (cnt[all[l++].second] == 0) d--;
    }
    cout << ans << endl;
  }
}
