#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
set<pair<int, int> > S;
int a[N], b[N], now[N], n;
int main() {
  for (int i = 1; i <= 6; i++) scanf("%d", &a[i]);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  sort(b + 1, b + n + 1);
  sort(a + 1, a + 6 + 1);
  for (int i = 1; i <= n; i++) now[i] = 1, S.insert(make_pair(-b[i] + a[1], i));
  int ans = 1e9, Min = b[1] - a[1];
  while (1) {
    ans = min(ans, -(*S.begin()).first - Min);
    int id = (*S.begin()).second;
    if (now[id] == 6) break;
    S.erase(make_pair(-b[id] + a[now[id]], id));
    now[id]++;
    Min = min(Min, b[id] - a[now[id]]);
    S.insert(make_pair(-b[id] + a[now[id]], id));
  }
  printf("%d\n", ans);
}
