#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  vector<long long> a(6);
  for (long long i = 0; i < 6; i++) {
    cin >> a[i];
  }
  long long n;
  cin >> n;
  vector<long long> b(n);
  vector<pair<long long, long long>> c;
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    for (long long j = 0; j < 6; j++) {
      c.push_back({b[i] - a[j], i});
    }
  }
  sort(c.begin(), c.end());
  vector<long long> cnt(n);
  long long cnt_col = 0;
  long long r = 0;
  long long ans = 2e18;
  for (long long l = 0; l < c.size(); l++) {
    while (r < c.size() && cnt_col < n) {
      if (cnt[c[r].second] == 0) {
        cnt_col++;
      }
      cnt[c[r].second]++;
      r++;
    }
    if (cnt_col < n) {
      break;
    }
    ans = min(ans, c[r - 1].first - c[l].first);
    cnt[c[l].second]--;
    if (cnt[c[l].second] == 0) {
      cnt_col--;
    }
  }
  cout << ans << endl;
  return 0;
}
