#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> a(6);
  for (int i = 0; i < 6; i++) {
    cin >> a[i];
  }
  int n;
  cin >> n;
  vector<pair<int, int>> vec;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    for (int j = 0; j < 6; j++) {
      vec.push_back({s - a[j], i});
    }
  }
  sort(vec.begin(), vec.end());
  int l = 0, r = 0;
  int cnt = 1;
  vector<int> nums(n, 0);
  nums[vec[0].second]++;
  int ans = 2000000000;
  for (int l = 0; l < vec.size(); l++) {
    while (r < vec.size() - 1 && cnt < n) {
      r++;
      if (nums[vec[r].second] == 0) {
        cnt++;
      }
      nums[vec[r].second]++;
    }
    if (cnt == n) {
      ans = min(ans, vec[r].first - vec[l].first);
    }
    if (nums[vec[l].second] == 1) {
      cnt--;
    }
    nums[vec[l].second]--;
  }
  cout << ans;
}
