#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
int a[N];
int b[N];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
int Max;
int main() {
  for (int i = 1; i <= 6; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 6 + 1, greater<int>());
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  sort(b + 1, b + n + 1, greater<int>());
  for (int i = 1; i <= n; i++) {
    q.push(make_pair(b[i] - a[1], 1));
    Max = max(Max, b[i] - a[1]);
  }
  int ans = 2e9;
  while (!q.empty()) {
    pair<int, int> it = q.top();
    q.pop();
    ans = min(ans, Max - it.first);
    if (it.second >= 6) break;
    q.push(
        make_pair(it.first + a[it.second] - a[it.second + 1], it.second + 1));
    Max = max(Max, it.first + a[it.second] - a[it.second + 1]);
  }
  printf("%d", ans);
  return 0;
}
