#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
const int N = 1e6 + 10;
int n, a[N], b[N];
struct uzi {
  int x, y;
  bool operator<(const uzi& t) const { return x < t.x; }
} p[N];
int cnt;
int vis[N], co;
int main() {
  ios::sync_with_stdio(false);
  for (int i = 1; i <= 6; i++) cin >> a[i];
  sort(a + 1, a + 7);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i];
  sort(b + 1, b + 1 + n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 6; j++) {
      int now = b[i] - a[j];
      p[++cnt] = {now, i};
    }
  }
  sort(p + 1, p + 1 + cnt);
  int ans = 1e9;
  for (int i = 1, j = 0; i <= cnt; i++) {
    while (j + 1 <= cnt && co < n) {
      ++j;
      if (!vis[p[j].y]) ++co;
      vis[p[j].y]++;
    }
    if (co == n) {
      ans = min(ans, p[j].x - p[i].x);
    }
    if (--vis[p[i].y] == 0) --co;
  }
  cout << ans << '\n';
  return 0;
}
