#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> p[1000001];
long long b[1000001], l = 1, r = 1, cnt = 0, a[7], n, Max = 1e9, now,
                      wlr[10000001], h = 1e9;
int main() {
  for (int i = 1; i <= 6; i++) {
    scanf("%lld", &a[i]);
  }
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
  }
  for (int i = 1; i <= 6; i++) {
    for (int j = 1; j <= n; j++) {
      p[++cnt] = make_pair(max(b[j] - a[i], 1ll), j);
    }
  }
  sort(p + 1, p + 1 + cnt);
  for (int l = 1, r = 1; r <= cnt; r++) {
    if (wlr[p[r].second] == 0) now++;
    wlr[p[r].second] += 1;
    for (; wlr[p[l].second] > 1; ++l) wlr[p[l].second]--;
    if (now == n) h = min(h, p[r].first - p[l].first);
  }
  cout << h << endl;
}
