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 a[100005], b[100005], c[100005], v[100005 << 2], n, m, ans = 1000000;
int A[100005], B[100005], C[100005];
int mn[100005 << 2], pos[100005 << 2], add[100005 << 2];
set<pair<int, int> > s;
set<pair<int, int> >::iterator tl, tr;
vector<int> t[100005 * 10];
void pushup(int x) {
  if (pos[x << 1] + mn[x << 1] < pos[x << 1 | 1] + mn[x << 1 | 1])
    mn[x] = mn[x << 1], pos[x] = pos[x << 1];
  else
    mn[x] = mn[x << 1 | 1], pos[x] = pos[x << 1 | 1];
}
void build(int l, int r, int rt) {
  if (l == r) {
    pos[rt] = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  pushup(rt);
}
void update(int x, int v) {
  mn[x] = max(mn[x], v);
  add[x] = max(add[x], v);
}
void pushdown(int x) {
  update(x << 1, add[x]);
  update(x << 1 | 1, add[x]);
  add[x] = 0;
}
void update(int l, int r, int rt, int L, int R, int v) {
  if (l == L && R == r) {
    update(rt, v);
    pos[rt] = l;
    return;
  }
  pushdown(rt);
  int mid = (l + r) >> 1;
  if (R <= mid)
    update(l, mid, rt << 1, L, R, v);
  else if (L > mid)
    update(mid + 1, r, rt << 1 | 1, L, R, v);
  else
    update(l, mid, rt << 1, L, mid, v),
        update(mid + 1, r, rt << 1 | 1, mid + 1, R, v);
  pushup(rt);
}
int get_pos(int x, int y) {
  tl = tr = s.lower_bound(make_pair(x, y));
  tl--;
  if ((*tr).second > y) return -1;
  while ((*tl).second <= y) {
    tr = tl;
    tl--;
    s.erase(tr);
  }
  s.insert(make_pair(x, y));
  return (*tl).first + 1;
}
int main() {
  cin >> n;
  build(0, n + 1, 1);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), v[++m] = a[i];
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]), v[++m] = b[i];
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]), v[++m] = c[i];
  sort(v + 1, v + m + 1);
  m = unique(v + 1, v + m + 1) - v - 1;
  for (int i = 1; i <= n; i++) a[i] = lower_bound(v + 1, v + m + 1, a[i]) - v;
  for (int i = 1; i <= n; i++) b[i] = lower_bound(v + 1, v + m + 1, b[i]) - v;
  for (int i = 1; i <= n; i++) c[i] = lower_bound(v + 1, v + m + 1, c[i]) - v;
  for (int i = 1; i <= m; i++) A[i] = B[i] = C[i] = n + 1;
  for (int i = 1; i <= n; i++)
    if (A[a[i]] == n + 1) A[a[i]] = i;
  for (int i = 1; i <= n; i++)
    if (B[b[i]] == n + 1) B[b[i]] = i;
  for (int i = 1; i <= n; i++)
    if (C[c[i]] == n + 1) C[c[i]] = i;
  for (int i = 1; i <= m; i++) t[A[i]].push_back(i);
  s.insert(make_pair(-1, 1000000));
  s.insert(make_pair(1000000, 0));
  for (int i = n + 1; i; i--) {
    for (int j = 0; j < t[i].size(); j++) {
      int k = t[i][j], p = B[k];
      int l = get_pos(p - 1, C[k]);
      if (l != -1) update(0, n + 1, 1, l, p - 1, C[k]);
    }
    if (mn[1] != n + 1 && pos[1] != n + 1)
      ans = min(ans, i + mn[1] + pos[1] - 1);
  }
  cout << ans << endl;
}
