#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1000;
int a[10], b[maxn];
int val[maxn][7];
int st[maxn];
vector<pair<int, int> > q;
int main() {
  ios::sync_with_stdio(0);
  for (int i = (1), iend = (6); i <= iend; i++) cin >> a[i];
  int n;
  int now_mx = 0;
  cin >> n;
  for (int i = (1), iend = (n); i <= iend; i++) cin >> b[i], st[i] = 1;
  int ans = 2e9;
  for (int i = (1), iend = (n); i <= iend; i++) {
    for (int j = (1), jend = (6); j <= jend; j++)
      val[i][j] = b[i] - a[j], q.push_back(make_pair(val[i][j], i));
    sort(val[i] + 1, val[i] + 1 + 6);
    now_mx = max(now_mx, val[i][1]);
  }
  sort(q.begin(), q.end());
  for (int i = 0; i < q.size(); i++) {
    int w = q[i].first, idx = q[i].second;
    ans = min(ans, now_mx - w);
    if (st[idx] == 6)
      break;
    else {
      now_mx = max(now_mx, val[idx][++st[idx]]);
    }
  }
  cout << ans;
  return 0;
}
