#include <bits/stdc++.h>
using namespace std;
multiset<long long> st;
multiset<long long> st1;
int s[6];
int n;
long long arr[1000002];
int vis[1000002];
vector<pair<long long, long long> > v;
int cnt = 0;
int main() {
  for (int i = 0; i < 6; i++) scanf("%d", s + i);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", arr + i);
  for (int i = 0; i < 6; i++)
    for (int j = 0; j < n; j++) v.push_back({arr[j] - s[i], j});
  sort(v.begin(), v.end());
  long long ans = 10e17;
  memset(vis, -1, sizeof vis);
  for (int i = 0; i < v.size(); i++) {
    pair<int, int> x = v[i];
    if (vis[x.second] != -1) st.erase(st.find(vis[x.second]));
    st.insert(x.first);
    vis[x.second] = x.first;
    if (st.size() == n) {
      ans = min(x.first - (*st.begin()), ans);
    }
  }
  cout << ans << endl;
  return 0;
}
