#include <bits/stdc++.h>
using namespace std;
long long int MAX = 1e7 + 1;
long long int mod = 1e9 + 7;
void solve() {
  long long int n, m;
  m = 6;
  vector<long long int> a(m);
  for (long long int i = 0; i < m; i++) cin >> a[i];
  cin >> n;
  vector<long long int> b(n);
  for (long long int i = 0; i < n; i++) cin >> b[i];
  vector<vector<long long int>> v(n, vector<long long int>(m));
  set<long long int> tot;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      v[i][j] = b[i] - a[j];
      tot.insert(v[i][j]);
    }
    sort(v[i].begin(), v[i].end());
  }
  set<pair<long long int, pair<long long int, long long int>>> s;
  for (long long int i = 0; i < n; i++) {
    s.insert({v[i][0], {i, 0}});
  }
  long long int ans = 1e15;
  for (auto &x : tot) {
    long long int mini = x;
    bool poss = true;
    while (s.begin()->first < mini) {
      pair<long long int, pair<long long int, long long int>> temp;
      temp = *s.begin();
      s.erase(s.begin());
      long long int i = temp.second.first;
      long long int str = temp.second.second;
      long long int fin = m;
      for (long long int j = str + 1; j < m; j++) {
        if (v[i][j] >= mini) {
          fin = j;
          break;
        }
      }
      if (fin == m) {
        poss = false;
        break;
      }
      temp = {v[i][fin], {i, fin}};
      s.insert(temp);
    }
    if (!poss) break;
    long long int maxi = s.rbegin()->first;
    ans = min(ans, maxi - mini);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
}
