#include <bits/stdc++.h>
const int N = 1e5 + 5;
long long n, a[7], b[N], f[N], cntp, ans = 10000000000ll;
std::pair<long long, long long> p[6 * N];
int main() {
  scanf("%lld%lld%lld%lld%lld%lld%lld", &a[1], &a[2], &a[3], &a[4], &a[5],
        &a[6], &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
  }
  for (int i = 1; i < 7; i++) {
    for (int j = 1; j <= n; j++) {
      p[++cntp] = std::make_pair(b[j] - a[i], j);
    }
  }
  std::sort(p + 1, p + 6 * n + 1);
  int l = 1, r = 1, pos = 0;
  for (; r <= cntp; r++) {
    if (!f[p[r].second]) pos++;
    f[p[r].second]++;
    while (f[p[l].second] > 1) {
      f[p[l].second]--;
      l++;
    }
    if (pos == n) ans = std::min(ans, p[r].first - p[l].first);
  }
  printf("%lld\n", ans);
  return 0;
}
