#include <bits/stdc++.h>
using namespace std;
constexpr long long N = 1e6 + 10;
long long a[10], b[N], cnt[N], r[N];
struct node {
  long long x, id;
};
vector<node> vec;
signed main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  for (long long i = 1; i <= 6; ++i) cin >> a[i];
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> b[i];
    for (long long j = 1; j <= 6; ++j) {
      vec.push_back({b[i] - a[j], i});
    }
  }
  sort(vec.begin(), vec.end(), [](node a, node b) { return a.x < b.x; });
  long long ans = 0x3f3f3f3f3f3f3f3f;
  long long sum = 0;
  long long i = 0, j = -1;
  while (i < n * 6) {
    while (sum < n && j < n * 6 - 1) {
      j++;
      cnt[vec[j].id]++;
      if (cnt[vec[j].id] == 1) sum++;
    }
    r[i] = sum == n ? j : -1;
    if (r[i] == -1) break;
    ans = min(ans, vec[r[i]].x - vec[i].x);
    cnt[vec[i].id]--;
    if (cnt[vec[i].id] == 0) sum--;
    i++;
  }
  cout << ans << endl;
  return 0;
}
