#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 500;
int gti(void) {
  char c = getchar();
  int ret = 0, st = 1;
  for (; c != '-' && !isdigit(c); c = getchar())
    ;
  if (c == '-') st = -1, c = getchar();
  for (; isdigit(c); c = getchar()) ret = ret * 10 + c - '0';
  return ret * st;
}
int a[10];
struct P {
  int val, id;
  bool operator<(const P &b) const { return val < b.val; }
};
priority_queue<P> st;
int main(void) {
  for (int i = 1; i <= 6; i++) a[i] = gti();
  sort(a + 1, a + 7);
  int n = gti(), dn = 1e9, ans = 1e9;
  for (int i = 1; i <= n; i++) {
    int b = gti();
    st.push((P){b - a[1], 1});
    dn = min(dn, b - a[1]);
  }
  while (st.size()) {
    P now = st.top();
    st.pop();
    ans = min(ans, now.val - dn);
    if (now.id < 6) {
      now.val += a[now.id] - a[now.id + 1];
      now.id++;
      dn = min(dn, now.val);
      st.push(now);
    } else
      break;
  }
  printf("%d\n", ans);
  return 0;
}
