#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> better(pair<long long, long long> a,
                                  pair<long long, long long> b) {
  if (a.first - a.second <= b.first - b.second)
    return a;
  else
    return b;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int senar[6];
  for (int x = 0; x < 6; x++) {
    cin >> senar[x];
  }
  sort(senar, senar + 6);
  int n;
  cin >> n;
  int data[n];
  for (int x = 0; x < n; x++) {
    cin >> data[x];
  }
  sort(data, data + n);
  pair<int, int> table[n + 1][10][10];
  pair<int, int> tmp = {1e9, -1e9};
  for (int x = 0; x <= n; x++) {
    for (int y = 0; y < 6; y++) {
      for (int z = 0; z < 6; z++) table[x][y][z] = tmp;
    }
  }
  for (int x = 0; x < 6; x++) {
    table[0][x][0] = {0, 0};
    table[1][x][0] = {data[0] - senar[x], data[0] - senar[x]};
  }
  for (int x = 1; x < n; x++) {
    for (int y = 0; y < 6; y++) {
      for (int z = 0; z < 6; z++) {
        for (int i = 0; i < 6; i++) {
          int dist = table[x + 1][y][z].first - table[x + 1][y][z].second;
          int a = max(data[x] - senar[y], table[x][z][i].first),
              b = min(data[x] - senar[y], table[x][z][i].second);
          if (dist >= 1e18) {
            table[x + 1][y][z] = {a, b};
          } else if (dist > a - b) {
            table[x + 1][y][z] = {a, b};
          }
        }
      }
    }
  }
  int ans = 1e9;
  for (int x = 0; x < 6; x++) {
    for (int y = 0; y < 6; y++)
      ans = min(ans, table[n][x][y].first - table[n][x][y].second);
  }
  cout << ans << "\n";
  return 0;
}
