#include <bits/stdc++.h>
int main() {
  std::vector<int> a(6);
  for (int i = 0; i < 6; ++i) {
    scanf("%d", &a[i]);
  }
  std::sort(a.begin(), a.end());
  int n;
  scanf("%d", &n);
  std::vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
  }
  std::set<std::tuple<int, int, int>> set;
  for (int i = 0; i < n; ++i) {
    set.emplace(b[i] - a[5], i, 5);
  }
  int result = 1e9 + 1;
  while (true) {
    result = std::min(
        result, std::get<0>(*std::prev(set.end())) - std::get<0>(*set.begin()));
    if (std::get<2>(*set.begin()) == 0) break;
    int w, x, y;
    std::tie(w, x, y) = *set.begin();
    set.erase(set.begin());
    set.emplace(b[x] - a[y - 1], x, y - 1);
  }
  printf("%d\n", result);
}
