#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int N = 2e6 + 1;
const long long mod = 1e9 + 7;
void solve() {
  int m = 6;
  vector<int> arr(m);
  for (int i = 0; i < m; i++) {
    cin >> arr[i];
  }
  int n;
  cin >> n;
  vector<array<int, 2>> store;
  vector<int> freq(n, 0);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    for (int j = 0; j < m; j++) {
      store.push_back({temp - arr[j], i});
    }
  }
  sort(store.begin(), store.end());
  int l = 0, r = 0;
  int ans = 2e9 + 10;
  while (l < store.size()) {
    while (r < store.size()) {
      if (cnt == n) {
        ans = min(ans, store[r - 1][0] - store[l][0]);
        break;
      }
      freq[store[r][1]]++;
      if (freq[store[r][1]] == 1) {
        cnt++;
      }
      r++;
    }
    if (r > store.size()) break;
    freq[store[l][1]]--;
    if (freq[store[l][1]] == 0) {
      cnt--;
    }
    l++;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  std::cout << std::fixed << std::setprecision(20);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
}
