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.
#include <bits/stdc++.h>
using namespace std;
int getint() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
  return x;
}
map<int, int> M;
int n, a[100010], b[100010], c[100010], idx;
int A[100010 * 3], B[100010 * 3], C[100010 * 3], no[100010 * 3];
bool cmp(int a, int b) { return A[a] > A[b]; }
void init() {
  n = getint();
  for (int i = 1; i <= n; i++) {
    a[i] = getint();
    M[a[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    b[i] = getint();
    M[b[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    c[i] = getint();
    M[c[i]] = 1;
  }
  for (map<int, int>::iterator it = M.begin(); it != M.end(); it++)
    it->second = ++idx;
}
void pre_build() {
  for (int i = 1; i <= idx; i++) {
    A[i] = B[i] = C[i] = 1000010;
    no[i] = i;
  }
  for (int i = 1; i <= n; i++)
    if (A[M[a[i]]] == 1000010) A[M[a[i]]] = i;
  for (int i = 1; i <= n; i++)
    if (B[M[b[i]]] == 1000010) B[M[b[i]]] = i;
  for (int i = 1; i <= n; i++)
    if (C[M[c[i]]] == 1000010) C[M[c[i]]] = i;
}
multiset<int> aS;
set<pair<int, int> > S;
void insert(int tb, int tc) {
  pair<int, int> tmp = make_pair(tb, tc);
  set<pair<int, int> >::iterator l, now, r = S.lower_bound(tmp);
  if (r->second >= tmp.second) return;
  l = now = S.insert(tmp).first;
  l--;
  aS.erase(aS.lower_bound(l->first + r->second));
  aS.insert(now->first + r->second);
  while (l->second < now->second) {
    r = l--;
    aS.erase(aS.lower_bound(l->first + r->second));
    S.erase(r);
  }
  aS.insert(l->first + now->second);
}
void process() {
  sort(no + 1, no + idx + 1, cmp);
  S.insert(make_pair(0, 1000010 * 2));
  S.insert(make_pair(1000010 * 2, 0));
  aS.insert(0);
  int ans = A[no[1]];
  A[idx + 1] = 0;
  for (int i = 1; i <= idx; i++) {
    insert(B[no[i]], C[no[i]]);
    if (A[no[i + 1]] + *aS.begin() < ans) ans = A[no[i + 1]] + *aS.begin();
  }
  printf("%d\n", ans);
}
int main() {
  init();
  pre_build();
  process();
  S.clear();
  aS.clear();
}
