#include <bits/stdc++.h>
using namespace std;
string tostr(long long a) {
  stringstream rr;
  rr << a;
  return rr.str();
}
long long pow(long long c, long long d) { return d == 0 ?: c * pow(c, d - 1); }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long> v(6);
  for (long long i = 0; i < 6; i++) {
    cin >> v[i];
  }
  long long n;
  cin >> n;
  vector<long long> ar[n + 10];
  set<pair<long long, long long>> st;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    for (long long j = 0; j < 6; j++) {
      ar[i].push_back(x - v[j]);
    }
    sort(ar[i].rbegin(), ar[i].rend());
    st.insert({ar[i].back(), i});
  }
  long long ans = 1000000000000000000;
  while (true) {
    ans = min(ans, st.rbegin()->first - st.begin()->first);
    long long ind = st.begin()->second;
    st.erase(st.begin());
    ar[ind].pop_back();
    if (ar[ind].size() == 0) break;
    st.insert({ar[ind].back(), ind});
  }
  cout << ans << endl;
  return 0;
}
