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;
struct rec {
  int val, pos, type;
} E[633333];
struct point {
  int a, x, y;
} P[633333];
struct rzz {
  int x, y;
  bool operator<(const rzz &B) const { return x == B.x ? y < B.y : x < B.x; }
};
bool cmp(const rec &i, const rec &j) { return i.val < j.val; }
bool cmp1(const point &i, const point &j) { return i.a > j.a; }
int n, tot, cnt, inf, ans, great[633333];
set<rzz> S;
set<int> Q;
set<rzz>::iterator it;
set<int>::iterator jt;
void Add(rzz A, rzz B, int key) {
  int val = A.x + B.y;
  if (A.x == n + 1) return;
  if (B.y == n + 1) return;
  if (key == 1) {
    great[val]++;
    if (great[val] == 1) Q.insert(val);
  } else {
    great[val]--;
    if (great[val] == 0) Q.erase(val);
  }
}
void Modify(set<rzz>::iterator it, int key) {
  rzz p = (rzz){0, 0};
  rzz nxt, pre;
  if (it == S.begin())
    pre = p;
  else
    pre = *--it, ++it;
  if (++it == S.end())
    nxt = p;
  else
    nxt = *it;
  --it;
  Add(pre, nxt, -key);
  Add(pre, *it, key);
  Add(*it, nxt, key);
  if (key == -1) S.erase(it);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    E[++tot] = (rec){x, i, 0};
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    E[++tot] = (rec){x, i, 1};
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    E[++tot] = (rec){x, i, 2};
  }
  sort(E + 1, E + 1 + tot, cmp);
  inf = n + 1;
  for (int i = 1, j = 1; i <= tot; i = j) {
    P[++cnt] = (point){inf, inf, inf};
    for (j = i; E[i].val == E[j].val; j++) {
      if (E[j].type == 0) P[cnt].a = min(P[cnt].a, E[j].pos);
      if (E[j].type == 1) P[cnt].x = min(P[cnt].x, E[j].pos);
      if (E[j].type == 2) P[cnt].y = min(P[cnt].y, E[j].pos);
    }
  }
  ans = 2333333;
  sort(P + 1, P + 1 + cnt, cmp1);
  if (P[1].a <= n) ans = P[1].a;
  rzz tmp;
  for (int i = 1; i <= cnt; i++) {
    tmp = (rzz){P[i].x, P[i].y};
    rzz *now = &tmp;
    it = S.upper_bound(*now);
    if (it == S.end() || it->y < now->y) {
      if (it != S.begin()) {
        it--;
        while (it->y <= now->y) {
          if (it == S.begin()) {
            Modify(it, -1);
            break;
          }
          Modify(it--, -1);
        }
      }
      S.insert(*now);
      Modify(S.lower_bound(*now), 1);
    }
    jt = Q.upper_bound(0);
    if (P[i + 1].a <= n && jt != Q.end()) ans = min(ans, P[i + 1].a + *jt);
  }
  printf("%d\n", ans);
}
