#include <bits/stdc++.h>
using namespace std;
int main() {
  int s[6];
  for (int i = 0; i < 6; i++) {
    cin >> s[i];
  }
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  map<int, int> mp;
  multiset<pair<int, int>> st;
  for (int i = 0; i < 6; i++) {
    for (int j = 0; j < n; j++) {
      st.insert(make_pair(ar[j] - s[i], j));
    }
  }
  auto ii = st.begin();
  int pr = ii->first;
  while (mp.size() != n) {
    mp[ii->second]++;
    pr = ii->first;
    ii++;
  }
  int ans = pr - st.begin()->first;
  auto i1 = st.begin();
  while (ii != st.end()) {
    mp[i1->second]--;
    while (ii != st.end() && mp[i1->second] == 0) {
      mp[ii->second]++;
      pr = ii->first;
      ii++;
    }
    int u = i1->second;
    i1++;
    if (mp[u] != 0) {
      ans = min(ans, pr - i1->first);
    }
  }
  cout << ans << '\n';
  return 0;
}
