#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 2e5 + 5;
const int inf = 0x3f3f3f3f;
pair<int, int> p[MAXN * 4];
int a[10];
int b[MAXN];
int vis[MAXN];
int main() {
  for (int i = 1; i <= 6; i++) cin >> a[i];
  sort(a + 1, a + 1 + 6);
  int n;
  cin >> n;
  int tot = 0;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    for (int j = 1; j <= 6; j++) {
      p[++tot].first = b[i] - a[j];
      p[tot].second = i;
    }
  }
  int ans = 2e9;
  sort(p + 1, p + 1 + tot);
  int pos1 = 1, pos2 = 1;
  int cnt = 0;
  while (pos2 <= tot) {
    if (!vis[p[pos2].second]) cnt++;
    vis[p[pos2].second]++;
    while (cnt == n && pos1 <= pos2) {
      ans = min(ans, p[pos2].first - p[pos1].first);
      vis[p[pos1].second]--;
      if (!vis[p[pos1].second]) cnt--;
      pos1++;
    }
    pos2++;
  }
  printf("%d\n", ans);
}
