#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[6], brr[(long long int)(1e5 + 1)], n;
  for (int i = 0; i < 6; i++) cin >> arr[i];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> brr[i];
  vector<pair<int, int>> my;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 6; j++) my.push_back({brr[i] - arr[j], i});
  sort(my.begin(), my.end());
  map<int, int> freq;
  int pre, next, tot;
  pre = next = tot = 0;
  while (tot != n) {
    freq[my[next].second]++;
    if (freq[my[next].second] == 1) tot++;
    next++;
  }
  next--;
  int ans = my[next].first - my[pre].first;
  while (1) {
    while (1) {
      if (freq[my[pre].second] == 1) break;
      freq[my[pre].second]--;
      pre++;
    }
    ans = min(ans, my[next].first - my[pre].first);
    next++;
    if (next == my.size()) break;
    freq[my[next].second]++;
  }
  cout << ans << endl;
}
