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

#include <bits/stdc++.h>
using namespace std;
int N;
int A[100000];
int B[100000];
int C[100000];
int ka[300000], kb[300000], kc[300000];
multiset<int> rt;
set<pair<int, int> > lis;
void insert(int x, int y) {
  set<pair<int, int> >::iterator it = lis.lower_bound(make_pair(x, -(1 << 29)));
  if (it->second >= y) return;
  it = lis.lower_bound(make_pair(x + 1, -(1 << 29)));
  set<pair<int, int> >::iterator it2 = it;
  it2--;
  rt.erase(rt.lower_bound(it2->first + 1 + it->second));
  while (1) {
    it = lis.lower_bound(make_pair(x + 1, -(1 << 29)));
    it--;
    if (it->second > y)
      break;
    else {
      it2 = it;
      it2--;
      rt.erase(rt.lower_bound(it2->first + 1 + it->second));
      lis.erase(it);
    }
  }
  it = lis.upper_bound(make_pair(x, y));
  it--;
  rt.insert(it->first + 1 + y);
  it = lis.upper_bound(make_pair(x, y));
  rt.insert(x + 1 + it->second);
  lis.insert(make_pair(x, y));
}
int main() {
  scanf("%d", &N);
  vector<int> v;
  for (int(i) = 0; (i) < (N); (i)++) scanf("%d", &A[i]), v.push_back(A[i]);
  for (int(i) = 0; (i) < (N); (i)++) scanf("%d", &B[i]), v.push_back(B[i]);
  for (int(i) = 0; (i) < (N); (i)++) scanf("%d", &C[i]), v.push_back(C[i]);
  sort((v).begin(), (v).end());
  (v).erase(unique((v).begin(), (v).end()), (v).end());
  for (int(i) = 0; (i) < (N); (i)++)
    A[i] = lower_bound((v).begin(), (v).end(), (A[i])) - (v).begin(),
    B[i] = lower_bound((v).begin(), (v).end(), (B[i])) - (v).begin(),
    C[i] = lower_bound((v).begin(), (v).end(), (C[i])) - (v).begin();
  rt.insert(1 << 30);
  lis.insert(make_pair(-1, 1 << 30));
  lis.insert(make_pair(1 << 30, -1 << 30));
  rt.insert(-1 << 30);
  int n = v.size();
  for (int(i) = 0; (i) < (n); (i)++) ka[i] = kb[i] = kc[i] = (1 << 29);
  for (int i = N - 1; i >= 0; i--) ka[A[i]] = i, kb[B[i]] = i, kc[C[i]] = i;
  int res = N * 3;
  for (int(i) = 0; (i) < (n); (i)++)
    if (ka[i] == (1 << 29)) insert(min(N, kb[i]), min(N * 5, kc[i]) + 1);
  res = min(res, int(*(++rt.begin())) + N);
  for (int i = N - 1; i >= 0; i--) {
    if (ka[A[i]] == i) insert(min(N, kb[A[i]]), min(N * 5, kc[A[i]]) + 1);
    res = min(res, int(*(++rt.begin())) + i);
  }
  printf("%d\n", res);
}
