#include <bits/stdc++.h>
using namespace std;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
const long long infi = 0x3f3f3f3f;
const long long mod = infl;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (long long i = 0; i < static_cast<long long>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res.push_back(static_cast<char>('0' + v[i]));
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
long long mygcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return mygcd(b, a % b);
}
long long mypow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
void solve() {
  vector<long long> str(6);
  for (long long i = 0; i < 6; i++) {
    cin >> str[i];
  }
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<pair<long long, long long>> vp;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 6; j++) {
      long long f = v[i] - str[j];
      long long s = i;
      vp.push_back({f, s});
    }
  }
  sort(vp.begin(), vp.end());
  map<long long, long long> mm;
  long long r = vp.size() - 1;
  long long l = r;
  mm[vp[r].second]++;
  long long ans = infl;
  while (r != 0) {
    if (mm.size() == n) {
      long long ans_temp = vp[r].first - vp[l].first;
      ans = min(ans, ans_temp);
      mm[vp[r].second]--;
      if (mm[vp[r].second] == 0) {
        mm.erase(vp[r].second);
      }
      r--;
      continue;
    }
    l--;
    if (l < 0) {
      break;
    }
    mm[vp[l].second]++;
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
