#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  vector<long long> a(6);
  for (long long i = 0; i < 6; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cin >> n;
  set<pair<long long, long long> > B;
  for (long long i = 0; i < n; ++i) {
    long long b;
    cin >> b;
    pair<long long, long long> p = {b - a[0], i - i};
    B.insert(p);
  }
  long long ans = 1000000000 + 10000;
  for (long long i = 1; i < 6 * n + 1; ++i) {
    auto end = B.end();
    end--;
    long long x = end->first;
    long long min1 = B.begin()->first;
    if (ans > x - min1) ans = x - min1;
    pair<long long, long long> num = *end;
    B.erase(end);
    if (!(num.second + 1 == 6)) {
      B.insert({num.first - a[num.second + 1] + a[num.second], num.second + 1});
    } else {
      break;
    }
  }
  cout << ans;
}
