#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int MAXM = 4e6 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
const unsigned long long BASE = 233;
const int base = 5;
mt19937_64 mt(time(0));
char rubbish[110];
bool GETDATA;
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - 48;
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
inline void write(long long x, char con = '\n') {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10, 0);
  putchar(x % 10 + '0');
  if (con) {
    printf("%c", con);
  }
}
long long N, M, K, Q;
long long a[MAXN];
vector<long long> b;
vector<pair<long long, long long> > c;
int cnt[MAXN];
void init() {
  b.clear();
  c.clear();
  for (int i = 0; i < N; i++) {
    cnt[i] = 0;
  }
}
void solve() {
  long long ans = INF;
  long long now, idx;
  for (int i = 1; i <= 6; i++) {
    a[i] = read();
  }
  sort(a + 1, a + 7);
  init();
  N = read();
  for (int i = 1; i <= N; i++) {
    now = read();
    b.push_back(now);
  }
  sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  for (int j = 0; j < b.size(); j++) {
    for (int i = 1; i <= 6; i++) {
      c.push_back(pair<long long, long long>(b[j] - a[i], j));
    }
  }
  sort(c.begin(), c.end());
  idx = 0;
  now = 0;
  for (auto x : c) {
    now += !cnt[x.second];
    cnt[x.second]++;
    while (cnt[c[idx].second] > 1) {
      cnt[c[idx].second]--;
      idx++;
    }
    if (now == b.size()) {
      ans = min(ans, x.first - c[idx].first);
    }
  }
  write(ans);
}
int main() {
  int T;
  T = 1;
  for (int t = 1; t <= T; t++) {
    GETDATA = false;
    solve();
  }
  return 0;
}
