#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 6, m;
  vector<int> a(n);
  for (int& i : a) cin >> i;
  cin >> m;
  vector<int> b(m);
  for (int& i : b) cin >> i;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  vector<pair<int, int>> d;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) d.push_back({i, j});
  sort(d.begin(), d.end(),
       [&](const pair<int, int> p1, const pair<int, int> p2) {
         return b[p1.second] - a[p1.first] < b[p2.second] - a[p2.first];
       });
  long long ans = 1e18;
  int r = 0;
  vector<int> used(m, 0);
  int cnt = 0;
  for (int i = 0; i < n * m; i++) {
    while (cnt < m && r < n * m) {
      if (!used[d[r].second]) {
        cnt++;
      }
      used[d[r].second]++;
      r++;
    }
    if (cnt == m) {
      int curMin = b[d[i].second] - a[d[i].first];
      int curMax = b[d[r - 1].second] - a[d[r - 1].first];
      ans = min(ans, 1ll * curMax - curMin);
    }
    used[d[i].second]--;
    if (!used[d[i].second]) cnt--;
  }
  cout << ans;
  return 0;
}
