#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> a(6);
  for (int i = 0; i < 6; ++i) {
    cin >> a[i];
  }
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  vector<pair<int, int>> c(n * 6 + 1);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 6; ++j) {
      c[i * 6 + j].first = b[i] - a[j];
      c[i * 6 + j].second = i;
    }
  }
  pair<int, int> h;
  h.first = 0;
  h.second = 0;
  c[n * 6] = h;
  sort(c.begin(), c.end());
  vector<int> was(n, 0);
  int j1 = 0, mini = 1e9, p = n;
  for (int i = 1; i < 6 * n + 1; ++i) {
    was[c[i].second]++;
    if (was[c[i].second] == 1) {
      p--;
    }
    if (p == 0) {
      j1 = i;
      break;
    }
  }
  was[0]++;
  for (int i = 1; i < n * 6 + 1; ++i) {
    was[c[i - 1].second]--;
    int ok = 0;
    if (was[c[i - 1].second] == 0) {
      ok = 1;
    }
    if (ok == 0) {
      mini = min(mini, c[j1].first - c[i].first);
    } else {
      for (int j = j1 + 1; j < 6 * n + 1; ++j) {
        was[c[j].second]++;
        if (was[c[j].second] == 1) {
          ok--;
          j1 = j;
          mini = min(mini, c[j1].first - c[i].first);
          break;
        }
      }
      if (ok != 0) {
        break;
      }
    }
  }
  cout << mini;
  return 0;
}
