using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("1");
WillReturn.Add("169");
WillReturn.Add("173");
WillReturn.Add("152");
WillReturn.Add("200");
//48
}
else if (InputPattern == "Input2") {
WillReturn.Add("7");
WillReturn.Add("7 9 9 4 6 3 5");
WillReturn.Add("1 1 1 1 1 1 1");
WillReturn.Add("1 1 1 1 1 1 1");
WillReturn.Add("1 1 1 1 1 1 1");
//2
}
else if (InputPattern == "Input3") {
WillReturn.Add("7");
WillReturn.Add("1 1 1 1 2 1 1");
WillReturn.Add("1 2 1 1 1 1 1");
WillReturn.Add("1 1 1 1 2 1 1");
WillReturn.Add("1 1 1 1 1 1 2");
//0
}
else if (InputPattern == "Input4") {
WillReturn.Add("5");
WillReturn.Add("287 690 413 420 138");
WillReturn.Add("813 873 223 415 907");
WillReturn.Add("261 330 361 747 787");
WillReturn.Add("958 672 544 126 345");
//70
}
else if (InputPattern == "Input5") {
WillReturn.Add("10");
WillReturn.Add("1682 2008 1135 1576 2450 1362 1518 1925 2212 1275");
WillReturn.Add("1993 1945 1312 1401 2027 1705 1086 2333 1787 1654");
WillReturn.Add("2257 1548 1219 1031 2613 2171 1866 1532 2800 1497");
WillReturn.Add("1062 1175 1984 1870 2059 1639 2107 1335 1289 2494");
//79
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static long UB;
static void Main()
{
List<string> InputList = GetInputList();
long[] AArr = InputList[1].Split(' ').Select(pX => long.Parse(pX)).ToArray();
long[] BArr = InputList[2].Split(' ').Select(pX => long.Parse(pX)).ToArray();
long[] CArr = InputList[3].Split(' ').Select(pX => long.Parse(pX)).ToArray();
long[] DArr = InputList[4].Split(' ').Select(pX => long.Parse(pX)).ToArray();
UB = AArr.GetUpperBound(0);
Array.Sort(AArr);
Array.Sort(BArr);
Array.Sort(CArr);
Array.Sort(DArr);
var AnswerList = new List<long>();
AnswerList.Add(DeriveAnswer(AArr, BArr, CArr, DArr));
AnswerList.Add(DeriveAnswer(BArr, AArr, CArr, DArr));
AnswerList.Add(DeriveAnswer(CArr, AArr, BArr, DArr));
AnswerList.Add(DeriveAnswer(DArr, AArr, BArr, CArr));
Console.WriteLine(AnswerList.Min());
}
// 最低値を取る配列と他の配列を引数として、解候補を返す
static long DeriveAnswer(long[] pArrMin, long[] pOtherArr1, long[] pOtherArr2, long[] pOtherArr3)
{
var AnswerList = new List<long>();
AnswerList.Add(long.MaxValue);
foreach (long EachMin in pArrMin) {
long ResultInd1 = ExecNibunhou_LowerBound(EachMin, pOtherArr1);
long ResultInd2 = ExecNibunhou_LowerBound(EachMin, pOtherArr2);
long ResultInd3 = ExecNibunhou_LowerBound(EachMin, pOtherArr3);
if (ResultInd1 == -1) break;
if (ResultInd2 == -1) break;
if (ResultInd3 == -1) break;
var ValList = new List<long>();
ValList.Add(pOtherArr1[ResultInd1]);
ValList.Add(pOtherArr2[ResultInd2]);
ValList.Add(pOtherArr3[ResultInd3]);
long Answer = ValList.Max() - EachMin;
AnswerList.Add(Answer);
}
return AnswerList.Min();
}
// 二分法で、Val以上で最小の値を持つ、添字を返す
static int ExecNibunhou_LowerBound(long pVal, long[] pArr)
{
if (pArr.Length == 0) return -1;
// 最後の要素がVal未満の特殊ケース
if (pVal > pArr.Last()) {
return -1;
}
// 最初の要素がVal以上の特殊ケース
if (pVal <= pArr[0]) {
return 0;
}
int L = 0;
int R = pArr.GetUpperBound(0);
while (L + 1 < R) {
int Mid = (L + R) / 2;
if (pArr[Mid] >= pVal) {
R = Mid;
}
else {
L = Mid;
}
}
return R;
}
}