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;
const int max_n = 1e5 + 20;
int sz;
int A[max_n], B[max_n], C[max_n], dp[max_n], cnt[max_n];
int n, a[max_n], b[max_n], c[max_n], d[max_n << 2], lazy[max_n << 2];
struct node {
  int mn, mx, ans;
  node(int a = 0, int b = 0, int c = 0) { mn = a, mx = b, ans = c; }
} seg[max_n << 2];
node Merge(node a, node b) {
  return node(min(a.mn, b.mn), max(a.mx, b.mx), min(a.ans, b.ans));
}
void change(int x, int id, int st) {
  seg[id] = node(lazy[id] = x, x, x <= n ? x + st : 3 * n);
}
inline void shift(int id, int st, int en) {
  if (!(~lazy[id])) return;
  int mid = st + en >> 1;
  change(lazy[id], id << 1, st);
  change(lazy[id], id << 1 | 1, mid);
  lazy[id] = -1;
}
void build(int id = 1, int st = 0, int en = n + 1) {
  lazy[id] = -1;
  if (en - st == 1) {
    seg[id] = node(dp[st], dp[st], dp[st] + st);
    return;
  }
  int mid = st + en >> 1;
  build(id << 1, st, mid);
  build(id << 1 | 1, mid, en);
  seg[id] = Merge(seg[id << 1], seg[id << 1 | 1]);
}
void update(int l, int r, int x, int id = 1, int st = 0, int en = n + 1) {
  if (r <= st || en <= l || seg[id].mn >= x) return;
  if (l <= st && en <= r && seg[id].mx < x) return change(x, id, st);
  shift(id, st, en);
  int mid = st + en >> 1;
  update(l, r, x, id << 1, st, mid);
  update(l, r, x, id << 1 | 1, mid, en);
  seg[id] = Merge(seg[id << 1], seg[id << 1 | 1]);
}
inline void prePro() {
  sort(d, d + sz);
  sz = unique(d, d + sz) - d;
  fill(A, A + sz, n + 1), fill(B, B + sz, n + 1), fill(C, C + sz, n + 1);
  for (int i = n; i; i--) {
    a[i] = lower_bound(d, d + sz, a[i]) - d,
    b[i] = lower_bound(d, d + sz, b[i]) - d,
    c[i] = lower_bound(d, d + sz, c[i]) - d;
    A[a[i]] = i;
    B[b[i]] = i;
    C[c[i]] = i;
  }
  int cur = 0;
  for (int i = 1; i <= n; i++) {
    cur += !cnt[a[i]]++;
    cur += !cnt[c[i]]++;
  }
  for (int i = 0, p = n; i <= n; i++) {
    cur += !cnt[b[i]]++;
    while (p && cnt[c[p]] > 1) cnt[c[p--]]--;
    dp[i] = (cur < sz ? 3 * n : p);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], d[sz] = a[i], sz++;
  for (int i = 1; i <= n; i++) cin >> b[i], d[sz] = b[i], sz++;
  for (int i = 1; i <= n; i++) cin >> c[i], d[sz] = c[i], sz++;
  prePro();
  build();
  int ans = n + seg[1].ans;
  for (int i = n; i; i--) {
    if (A[a[i]] == i) update(0, B[a[i]], C[a[i]]);
    ans = min(ans, i + seg[1].ans - 1);
  }
  cout << ans << endl;
  return 0;
}
