#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e5 + 7;
const int MOD = 1e9 + 7;
int n, a[7], b[MXN], ans = MOD * 2, cnt[MXN], k;
pair<int, int> c[MXN * 6];
int main() {
  ios_base::sync_with_stdio(0);
  for (int i = 1; i <= 6; i++) {
    cin >> a[i];
  }
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    int ind = (i - 1) * 6;
    for (int j = 1; j <= 6; j++) {
      c[ind + j] = {x - a[j], i};
    }
  }
  sort(c + 1, c + (n * 6) + 1);
  int L = 1;
  for (int i = 1; i <= n * 6; i++) {
    cnt[c[i].second]++;
    if (cnt[c[i].second] == 1) k++;
    while (k > n) {
      cnt[c[L].second]--;
      if (!cnt[c[L].second]) k--;
      L++;
    }
    if (k == n) {
      while (cnt[c[L].second] > 1) {
        cnt[c[L].second]--;
        L++;
      }
      ans = min(ans, c[i].first - c[L].first);
    }
  }
  cout << ans;
  return 0;
}
