#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[7], n;
vector<pair<int, int> > t;
int vis[N];
int main() {
  for (int i = 0; i < 6; i++) cin >> a[i];
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < 6; j++) t.push_back({x - a[j], i});
  }
  int l = 0, r = 0, num = 0, ans = 0x3f3f3f3f;
  sort(t.begin(), t.end());
  while (r < t.size()) {
    if (!vis[t[r].second]) num++;
    vis[t[r].second]++;
    while (num == n && l <= r) {
      ans = min(ans, t[r].first - t[l].first);
      if (--vis[t[l].second] == 0) num--;
      l++;
    }
    r++;
  }
  cout << ans << endl;
}
