#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 1e5 + 100;
int n, val[maxn], a[10];
void solve() {
  for (int i = 1; i <= 6; i++) scanf("%d", a + i);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", val + i);
  sort(a + 1, a + 7);
  sort(val + 1, val + 1 + n);
  int ans = 0x7fffffff;
  for (int i = 1; i <= n; i++)
    for (int p = 1; p <= 6; p++) {
      const int mi = val[i] - a[p];
      int mx = 0x7fffffff, l = mi, r = val[n];
      auto chk = [](const int mi, const int lim) -> bool {
        int p = 1;
        for (int i = 1; i <= 6; i++) {
          const int x = upper_bound(val + p, val + 1 + n, lim + a[i]) - val;
          if (val[p] - a[i] < mi) return false;
          p = x;
          if (p == n + 1) return true;
        }
        return false;
      };
      while (l <= r) {
        const int mid = (l + r) >> 1;
        if (chk(mi, mid))
          mx = mid, r = mid - 1;
        else
          l = mid + 1;
      }
      ans = min(ans, mx - mi);
    }
  printf("%d\n", ans);
}
int t;
int main() {
  solve();
  return 0;
}
