There are three arrays a, b and c. Each of them consists of n integers. SmallY wants to find three integers u, v, w (0 ≤ u, v, w ≤ n) such that the following condition holds: each number that appears in the union of a, b and c, appears either in the first u elements of a, or in the first v elements of b, or in the first w elements of c. Of course, SmallY doesn't want to have huge numbers u, v and w, so she wants sum u + v + w to be as small as possible.

Please, help her to find the minimal possible sum of u + v + w.

Input

The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an — array a. The third line contains the description of array b in the same format. The fourth line contains the description of array c in the same format. The following constraint holds: 1 ≤ ai, bi, ci ≤ 109.

Output

Print a single integer — the minimum possible sum of u + v + w.

Examples

Input

3
1 1 101
1 2 1
3 2 1


Output

5

Input

5
1 1 2 2 3
2 2 4 3 3
3 3 1 1 1


Output

5

Note

In the first example you should choose u = 3, v = 0, w = 2. 

In the second example you should choose u = 1, v = 3, w = 1.
1
2
3
2
 8
190409007 190409007 352375776 190409007 352375776 352375776 352375776 352375776
190409007 190409007 190409007 190409007 190409007 352375776 352375776 190409007
190409007 352375776 352375776 190409007 190409007 190409007 352375776 352375776
 1
1
1
1
 1
377489979
588153796
588153796
 2
1 1
2 2
3 3
 4
1 1 1 1
1 1 1 1
1 1 1 1
 2
1 2
2 2
1 1
 3
1 1 2
1 1 3
1 1 4

2
 2
 1
 2
 3
 1
 2
 9

import fileinput
import copy

i=0
for line in fileinput.input():
    if i==0:
        n = int(line)
        myLists = [[0]*n for i in range(3)]
        i+=1
    else:
        myLists[i-1] = [int(i) for i in line.split()]
        i+=1

myListsCopy = copy.deepcopy(myLists)

def sortUnion(listToUnionSort):
    if len(listToUnionSort) ==1:
        ans = list(set(listToUnionSort))
        ans.sort()
        return ans
    else:
        ans = listToUnionSort[0]
        for i in range(1,len(listToUnionSort)):
            ans.extend(listToUnionSort[i])
        ans = list(set(ans))
        ans.sort()
        return ans


myUnionList = sortUnion(myListsCopy)

L1 = len(myUnionList)
L = len(myLists[0])
myUnionDict = {}

for i in range(L1):
    k = []
    for j in range(3):
        if myUnionList[i] in myLists[j]:
            k.append(myLists[j].index(myUnionList[i]))
        else:
            k.append(L)
    myUnionDict[myUnionList[i]] = k

#print(myUnionDict)
   



def myMiniMax(myLists,myDict, L):
    valuesL = list(myDict.values())
    if len(valuesL) == 0:
        return [L]
    myMin = [ min(i) for i in valuesL ]
    myMax = max(myMin)
    relNum = [myLists[j][myMax] for j in range(len(myLists))]
    maxRelNum = max(relNum)
    myMaxVec = [i == maxRelNum for i in relNum]
    return [myMax, myMaxVec]

def myPruneFunc(myLists, myDict, myListIndex, myIndex):
    valuesToRemove = list(set(myLists[myListIndex][0:(myIndex+1)]))
    for i in valuesToRemove:
        if i in list(myDict.keys()):
            myDict.pop(i)
    for i in list(myDict.keys()):
        del myDict[i][myListIndex]
    del myLists[myListIndex]

def myRecFunc(myLists, myDict, currentSum, L):
    myMax = myMiniMax(myLists,myDict,L)
    if myMax[0] == L:
        return currentSum
    if len(myLists) == 0:
        return currentSum
    if len(myLists[0])==1:
        return currentSum+1+myMax[0]
    else:
        numCandidates = sum(myMax[1])
        candIndex = []
        for i in range(0, len(myMax[1])):
            if myMax[1][i]:
                candIndex.append(i)
        ansList = []
        copiedLists = []
        copiedDict = []
        for i in range(len(candIndex)):
            copiedLists.append(copy.deepcopy(myLists))
            copiedDict.append(copy.deepcopy(myDict))
            myPruneFunc(copiedLists[i],copiedDict[i],candIndex[i],myMax[0])
            ansList.append(myRecFunc(copiedLists[i],copiedDict[i],currentSum+1+myMax[0],L))
        return min(ansList)

print(myRecFunc(myLists,myUnionDict,0,L))
        
            
        

        









def operate(A):
    myMin = [ min(i) for i in list(A.values())]
    myIndex = myMin.index(max(myMin))
    valueInterest = max(A[myIndex])
    indexInterest = A[myIndex].index(valueInterest)
    for i in range(myIndex+1):
        A.pop(myLists[indexInterest][i])
    


