#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = INT_MAX;
  vector<int> a(6);
  for (int i = 0; i < 6; i++) {
    cin >> a[i];
  }
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector<pair<int, int>> lad;
  lad.reserve(6 * n);
  for (int i = 0; i < 6; i++)
    for (int j = 0; j < n; j++) {
      lad.push_back({b[j] - a[i], j});
    }
  sort(lad.begin(), lad.end());
  int cnt = 0;
  vector<int> v(n, 0);
  int cur = 0;
  int j = 0;
  bool flag = true;
  for (int i = 0; i < lad.size(); i++) {
    if (i != 0) {
      if (0 == --v[lad[i - 1].second]) cnt--;
    }
    if (cnt == n) {
      if (lad[j].first - lad[i].first < ans) ans = lad[j].first - lad[i].first;
      continue;
    }
    for (; j < lad.size(); j++, flag = true) {
      if (flag && 1 == ++v[lad[j].second]) {
        cnt++;
      }
      if (cnt == n) {
        if (lad[j].first - lad[i].first < ans)
          ans = lad[j].first - lad[i].first;
        flag = false;
        break;
      }
    }
    if (j == lad.size() - 1) break;
  }
  cout << ans;
}
