#include <bits/stdc++.h>
using namespace std;
int n, a[6], b, cnt[100010];
vector<pair<int, int> > v;
int main() {
  for (int i = 0; i < 6; i++) cin >> a[i];
  sort(a, a + 6);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b;
    for (int j = 0; j < 6; j++) v.push_back(make_pair(b - a[j], i));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) cnt[i] = 0;
  int l = 0, c = 0, res = 1234567890;
  for (int r = 0; r < v.size(); r++) {
    if (cnt[v[r].second]++ == 0) c++;
    while (l <= r && cnt[v[l].second] > 1) cnt[v[l++].second]--;
    if (c == n) res = min(res, v[r].first - v[l].first);
  }
  cout << res << "\n";
}
