#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 20;
const long long LLINF = 1e18;
const int MAXN = 1e5 + 10;
int n;
int a[6];
int b[MAXN];
int cnt[MAXN];
pair<int, int> all[6 * MAXN];
int main() {
  for (int i = 0; i < 6; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &n);
  if (n == 1) {
    printf("%d\n", 0);
    return 0;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    for (int j = 0; j < 6; j++) {
      all[6 * i + j] = {b[i] - a[j], i};
    }
  }
  sort(all, all + 6 * n);
  int best_ans = INF;
  int l = 0, r = 0;
  cnt[all[0].second] = 1;
  int help = 1;
  while (r < 6 * n) {
    if (help == n) {
      best_ans = min(best_ans, all[r].first - all[l].first);
      cnt[all[l].second]--;
      if (cnt[all[l].second] == 0) help--;
      l++;
    } else {
      r++;
      if (cnt[all[r].second] == 0) help++;
      cnt[all[r].second]++;
    }
  }
  printf("%d\n", best_ans);
  return 0;
}
