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;
#pragma GCC optimize("Ofast")
const long long maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 10;
long long n, m, k;
long long mn[maxn << 2], mx[maxn << 2], ans[maxn << 2], la[maxn << 2];
void build(long long v = 1, long long tl = 0, long long tr = n) {
  ans[v] = tl;
  if (tl == tr) return;
  long long tm = (tl + tr) >> 1;
  build(v << 1, tl, tm);
  build(v << 1 | 1, tm + 1, tr);
}
void shift(long long v) {
  if ((v << 1 | 1) < (maxn << 2)) {
    la[v << 1] += la[v];
    la[v << 1 | 1] += la[v];
  }
  ans[v] += la[v];
  mn[v] += la[v];
  mx[v] += la[v];
  la[v] = 0;
}
void up(long long l, long long r, long long val, long long v = 1,
        long long tl = 0, long long tr = n) {
  shift(v);
  if (l > r || mn[v] >= val) return;
  ;
  if (tl == l && tr == r && mn[v] == mx[v]) {
    la[v] += val - mx[v];
    shift(v);
    return;
  }
  long long tm = (tl + tr) >> 1;
  up(l, min(tm, r), val, v << 1, tl, tm);
  up(max(tm + 1, l), r, val, v << 1 | 1, tm + 1, tr);
  mn[v] = min(mn[v << 1], mn[v << 1 | 1]);
  ans[v] = min(ans[v << 1], ans[v << 1 | 1]);
  mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
}
long long qu(long long l, long long r, long long v = 1, long long tl = 0,
             long long tr = n) {
  shift(v);
  if (l > r) return inf;
  if (tl == l && tr == r) return ans[v];
  long long tm = (tl + tr) >> 1;
  return min(qu(l, min(tm, r), v << 1, tl, tm),
             qu(max(tm + 1, l), r, v << 1 | 1, tm + 1, tr));
}
void add(long long a, long long b) {
  if (!a) a = n + 1;
  if (b)
    up(0, a - 1, b);
  else
    up(0, a - 1, inf);
}
long long a[maxn], b[maxn], c[maxn];
long long pos[maxn][3];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long m = 3 * n;
  map<long long, long long> mp;
  long long lst = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (!mp.count(a[i])) mp.insert({a[i], ++lst});
    a[i] = mp[a[i]];
    if (!pos[a[i]][0]) pos[a[i]][0] = i;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> b[i];
    if (!mp.count(b[i])) mp.insert({b[i], ++lst});
    b[i] = mp[b[i]];
    if (!pos[b[i]][1]) pos[b[i]][1] = i;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> c[i];
    if (!mp.count(c[i])) mp.insert({c[i], ++lst});
    c[i] = mp[c[i]];
    if (!pos[c[i]][2]) pos[c[i]][2] = i;
  }
  build();
  for (long long i = 1; i <= m; i++) {
    if (!pos[i][1] && !pos[i][2]) continue;
    if (!pos[i][0]) add(pos[i][1], pos[i][2]);
  }
  long long Ans = m;
  for (long long i = n; i >= 1; i--) {
    Ans = min(Ans, qu(0, n) + i);
    if (pos[a[i]][0] != i) continue;
    add(pos[a[i]][1], pos[a[i]][2]);
  }
  Ans = min(Ans, qu(0, n));
  cout << Ans;
}
