#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
pair<int, int> c[N * 6];
int a[9], b[N], n, i, j, xb, cnt[N], z, ans = 1 << 30;
inline void mdy(int i, int v) {
  z -= cnt[i] > 0;
  cnt[i] += v;
  z += cnt[i] > 0;
}
int main() {
  for (i = 1; i <= 6; ++i) scanf("%d", a + i);
  scanf("%d", &n);
  for (i = 1; i <= n; ++i)
    for (scanf("%d", b + i), j = 1; j <= 6; ++j) c[++xb] = {b[i] - a[j], i};
  sort(c + 1, c + xb + 1);
  for (i = 1, j = 0; i <= xb; ++i) {
    for (; j < xb && z < n; mdy(c[++j].second, 1))
      ;
    if (z == n) ans = min(ans, c[j].first - c[i].first);
    mdy(c[i].second, -1);
  }
  printf("%d\n", ans);
}
