#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 17;
int a[6], b[100010], t[N + N];
map<int, vector<pair<int, int> > > m;
int main() {
  int n;
  for (int i = 0; i < 6; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  sort(b, b + n);
  n = unique(b, b + n) - b;
  sort(a, a + 6);
  int k = unique(a, a + 6) - a;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int c[7];
    for (int j = 0; j < k; j++) {
      c[j] = b[i] - a[j];
      v.push_back(c[j]);
    }
    reverse(c, c + k);
    c[k] = 2001001001;
    t[i + N] = c[0];
    for (int j = 0; j < k; j++) {
      m[c[j]].push_back(make_pair(i, c[j + 1]));
    }
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  for (int i = N - 1; i > 0; i--) {
    t[i] = max(t[i + i], t[i + i + 1]);
  }
  int ans = 1001001001;
  for (int i = 0; i < v.size(); i++) {
    ans = min(ans, t[1] - v[i]);
    for (int j = 0; j < m[v[i]].size(); j++) {
      int r = m[v[i]][j].first, x = m[v[i]][j].second;
      r += N;
      t[r] = x;
      while (r > 1) {
        r /= 2;
        t[r] = max(t[r + r], t[r + r + 1]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
