#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void one();
int main() {
  fastio();
  int t = 1;
  for (int i = 0; i < t; ++i) {
    one();
  }
  return 0;
}
void one() {
  vector<int> a(6);
  for (int i = 0; i < 6; ++i) cin >> a[i];
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; ++i) cin >> b[i];
  vector<pair<int, int>> x;
  for (int j = 0; j < 6; ++j) {
    for (int i = 0; i < n; ++i) {
      x.push_back({b[i] - a[j], i});
    }
  }
  sort(x.begin(), x.end());
  long long ans = x.back().first - x.front().first;
  int sum = 0;
  vector<int> cnt(n);
  int r = -1;
  for (int l = 0; l < x.size(); ++l) {
    while (sum < n) {
      if (r == x.size() - 1) {
        break;
      }
      r++;
      cnt[x[r].second]++;
      if (cnt[x[r].second] == 1) {
        sum++;
      }
    }
    if (sum == n) {
      ans = min(ans, (long long)x[r].first - x[l].first);
    }
    cnt[x[l].second]--;
    if (cnt[x[l].second] == 0) {
      sum--;
    }
  }
  cout << ans << "\n";
}
