#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v(6);
  for (int i = 0; i < 6; ++i) cin >> v[i];
  int n;
  cin >> n;
  vector<pair<int, int>> a;
  int num;
  for (int i = 0; i < n; ++i) {
    cin >> num;
    for (int j = 0; j < 6; ++j) {
      a.push_back({num - v[j], i});
    }
  }
  sort(a.begin(), a.end());
  int ans = 1e9 + 7;
  map<int, int> mp;
  int t = 0;
  int l = 0;
  for (int i = 0; i < a.size(); ++i) {
    int k = a[i].second;
    if (mp[k] == 0) {
      t++;
    }
    mp[k]++;
    while (mp[a[l].second] > 1) {
      mp[a[l].second]--;
      l++;
    }
    if (t == n) {
      ans = min(ans, a[i].first - a[l].first);
    }
  }
  cout << ans;
}
