#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int a[6];
  for (int i = 0; i < 6; i++) cin >> a[i];
  sort(a, a + 6);
  int n;
  cin >> n;
  long long int b[n];
  for (int i = 0; i < n; i++) cin >> b[i];
  sort(b, b + n);
  long long int ans = b[n - 1] - b[0];
  vector<pair<long long int, int>> c;
  for (int i = 0; i < 6; i++) {
    for (int j = 0; j < n; j++) {
      c.push_back({b[j] - a[i], j});
    }
  }
  sort(c.begin(), c.end());
  int cnt[n];
  memset(cnt, 0, sizeof(cnt));
  int ply = 0;
  int i = 0, j = -1;
  while (j < (int)c.size() - 1) {
    j++;
    int ins = c[j].second;
    if (!cnt[ins]) ply++;
    cnt[ins]++;
    while (cnt[c[i].second] > 1) cnt[c[i].second]--, i++;
    if (ply == n) {
      ans = min(ans, c[j].first - c[i].first);
    }
  }
  cout << ans << "\n";
  return 0;
}
