#include <bits/stdc++.h>
using namespace std;
int a[10], b[100005], c[100005][10];
int idx[100005];
int main() {
  for (int i = 1; i <= 6; i++) scanf("%d", &a[i]);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]), idx[i] = 1;
  vector<int> v;
  int mn = 1e9;
  for (int i = 1; i <= n; i++) {
    int mx = 0;
    for (int j = 1; j <= 6; j++) {
      c[i][j] = b[i] - a[j];
      v.emplace_back(c[i][j]);
      mx = max(mx, c[i][j]);
    }
    sort(c[i] + 1, c[i] + 1 + 6);
    mn = min(mn, mx);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  multiset<int> cur;
  int ans = 1e9;
  for (int i = 1; i <= n; i++) {
    cur.insert(c[i][1]);
    pq.push(make_pair(c[i][1], i));
  }
  ans = *cur.rbegin() - *cur.begin();
  for (int i = 0; i < v.size(); i++) {
    if (v[i] > mn) break;
    while (!pq.empty()) {
      int u = pq.top().second;
      int val = pq.top().first;
      if (val < v[i]) {
        pq.pop();
        cur.erase(cur.find(c[u][idx[u]]));
        idx[u]++;
        if (idx[u] <= 6) {
          cur.insert(c[u][idx[u]]);
          pq.push(make_pair(c[u][idx[u]], u));
        }
      } else
        break;
    }
    ans = min(ans, *cur.rbegin() - *cur.begin());
  }
  printf("%d\n", ans);
}
