#include <bits/stdc++.h>
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
int main() {
  std::ios::sync_with_stdio(false);
  std::vector<long long> a(6);
  for (long long& i : a) std::cin >> i;
  int n;
  std::cin >> n;
  std::vector<long long> v(n);
  for (long long& i : v) std::cin >> i;
  std::multiset<pll> possible;
  std::multiset<long long> current;
  std::vector<std::multiset<long long>> avail(n);
  for (int i = 0; i < n; i++) {
    for (auto& j : a) {
      possible.insert({v[i] - j, i});
      avail[i].insert(v[i] - j);
    }
    current.insert(*avail[i].begin());
  }
  long long ans = 1e18;
  while (!possible.empty()) {
    auto [val, i] = *possible.begin();
    possible.erase(possible.begin());
    ans = std::min(ans, *(--current.end()) - val);
    avail[i].erase(avail[i].begin());
    if (avail[i].empty()) {
      break;
    }
    current.erase(current.find(val));
    current.insert(*avail[i].begin());
  }
  std::cout << ans << std::endl;
  return 0;
}
