#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  vector<long long> a;
  for (long long i = 0; i < 6; ++i) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  vector<vector<long long> > p;
  long long n;
  cin >> n;
  vector<long long> b;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    b.push_back(x);
  }
  for (long long i = 0; i < 6; ++i) {
    for (long long j = 0; j < n; ++j) {
      p.push_back({b[j] - a[i], j});
    }
  }
  sort(p.begin(), p.end());
  long long uk1 = 0, uk2 = 0;
  vector<long long> used(n, 0);
  long long cnt = 0;
  long long ans = 1000000000000000;
  while (uk2 < p.size()) {
    while (uk2 < p.size() && cnt < n) {
      used[p[uk2][1]]++;
      if (used[p[uk2][1]] == 1) {
        cnt++;
      }
      uk2++;
    }
    if (cnt == n) {
      ans = min(ans, p[uk2 - 1][0] - p[uk1][0]);
    }
    used[p[uk1][1]]--;
    if (used[p[uk1][1]] == 0) {
      cnt--;
    }
    uk1++;
  }
  cout << ans;
}
