#include <bits/stdc++.h>
using namespace std;
const int N = 100020, M = 10, INF = 1e9 + 5;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int n, ans = INF, Minb = INF, a[M], b[N], tmp[6 * N];
struct node {
  int k, num;
  bool operator<(node x) const { return num < x.num; }
};
priority_queue<node> q;
bool cmp(int in1, int in2) { return in1 > in2; }
int main() {
  for (int i = 1; i <= 6; i++) a[i] = read();
  sort(a + 1, a + 6 + 1);
  n = read();
  for (int i = 1; i <= n; i++) {
    b[i] = read();
    Minb = min(Minb, b[i]);
    for (int j = 1; j <= 6; j++) tmp[(i - 1) * 6 + j] = b[i] - a[j];
  }
  sort(tmp + 1, tmp + 6 * n + 1, cmp);
  for (int i = 1; i <= n; i++) q.push({0, b[i]});
  for (int i = 1; i <= 6 * n; i++)
    if (tmp[i] <= Minb - a[1]) {
      while (1) {
        node hd = q.top();
        if (hd.k == 6 || hd.num + a[hd.k] - a[hd.k + 1] < tmp[i]) break;
        q.pop();
        q.push({hd.k + 1, hd.num + a[hd.k] - a[hd.k + 1]});
      }
      ans = min(ans, q.top().num - tmp[i]);
    }
  cout << ans;
  return 0;
}
