#include <bits/stdc++.h>
using namespace std;
vector<long long int> A, V;
int n;
long long int solve(int column) {
  vector<vector<long long int> > cols(n - 1);
  for (int i = 1; i < n; ++i) {
    long long int x = -1e10, y = 1e10;
    for (int j = 0; j < 6; ++j) {
      if (V[i] - A[j] <= column) x = max(x, V[i] - A[j]);
      if (V[i] - A[j] >= column) y = min(y, V[i] - A[j]);
    }
    cols[i - 1] = {x, y};
  }
  sort(cols.begin(), cols.end());
  long long int maxy = column;
  long long int ans = 1e10;
  for (int i = 0; i < cols.size(); ++i) {
    ans = min(ans, maxy - cols[i][0]);
    maxy = max(maxy, cols[i][1]);
  }
  ans = min(ans, maxy - column);
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  A = vector<long long int>(6);
  for (int i = 0; i < 6; ++i) cin >> A[i];
  cin >> n;
  V = vector<long long int>(n);
  for (int i = 0; i < n; ++i) cin >> V[i];
  sort(A.begin(), A.end());
  sort(V.begin(), V.end());
  long long int minimum = 1e18;
  for (int i = 0; i < 6; ++i) {
    minimum = min(minimum, solve(V[0] - A[i]));
  }
  cout << minimum << '\n';
}
