#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a[6];
  for (int i = 0; i < 6; i++) cin >> a[i];
  int n;
  cin >> n;
  pair<long long, long long> p[n * 6];
  long long t;
  long long id = 0;
  for (int i = 0; i < n; i++) {
    cin >> t;
    for (int j = 0; j < 6; j++) p[id++] = {t - a[j], i};
  }
  sort(p, p + n * 6);
  long long ans = LLONG_MAX;
  long long i = 0, j = 0;
  unordered_map<long long, int> mp;
  while (j < 6 * n) {
    if ((int)mp.size() == n) {
      ans = min(ans, p[j - 1].first - p[i].first);
      mp[p[i].second]--;
      if (mp[p[i].second] == 0) mp.erase(p[i].second);
      i++;
    } else {
      mp[p[j].second]++;
      j++;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
