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;
const int N = 1e5 + 5;
struct node {
  int mn, mx, ans;
  node(int a = 0, int b = 0, int c = 0) { mn = a, mx = b, ans = c; }
} seg[N << 2];
int A[N], B[N], C[N], dp[N], cnt[N];
int n, m, a[N], b[N], c[N], d[N << 2], lazy[N << 2];
inline node merge(node a, node b) {
  return node(min(a.mn, b.mn), max(a.mx, b.mx), min(a.ans, b.ans));
}
inline 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 readInput() {
  cin >> n;
  for (int i = 1; i <= n; d[m++] = a[i++]) cin >> a[i];
  for (int i = 1; i <= n; d[m++] = b[i++]) cin >> b[i];
  for (int i = 1; i <= n; d[m++] = c[i++]) cin >> c[i];
}
inline void prepare() {
  sort(d, d + m);
  m = unique(d, d + m) - d;
  fill(A, A + m, n + 1), fill(B, B + m, n + 1), fill(C, C + m, n + 1);
  for (int i = n; i; i--) {
    A[a[i] = lower_bound(d, d + m, a[i]) - d] = i;
    B[b[i] = lower_bound(d, d + m, b[i]) - d] = i;
    C[c[i] = lower_bound(d, d + m, c[i]) - d] = 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 < m ? 3 * n : p);
  }
}
inline void solve() {
  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;
}
inline void program() {
  readInput();
  prepare();
  build();
  solve();
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  program();
  return 0;
}
