#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T>>;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 10;
int n, a[7], b[maxN], cnt[maxN];
vector<pair<int, int>> vec;
void solve() {
  for (int i = 1; i <= (int)(6); ++i) {
    cin >> a[i];
  }
  cin >> n;
  for (int i = 1; i <= (int)(n); ++i) {
    cin >> b[i];
  }
  for (int i = 1; i <= (int)(n); ++i) {
    for (int j = 1; j <= (int)(6); ++j) {
      vec.emplace_back(b[i] - a[j], i);
    }
  }
  sort((vec).begin(), (vec).end());
  int num = 0, idx = 0, ans = 2e9;
  for (int i = 0; i < (int)(vec.size()); ++i) {
    num += (cnt[vec[i].second] == 0);
    cnt[vec[i].second]++;
    while (idx < i && cnt[vec[idx].second] > 1) {
      cnt[vec[idx].second]--;
      idx++;
    }
    if (num == n) {
      uin(ans, vec[i].first - vec[idx].first);
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
