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 MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 3;
const int MAXK = (int)3e5 + 3;
const int infint = (int)1e9 + 3;
const long long inf = (long long)1e12;
int a[MAXN], b[MAXN], c[MAXN], n, fir[MAXK], sec[MAXK], thir[MAXK], sz,
    mn[MAXN << 2], mx[MAXN << 2], ans[MAXN << 2], lazy[MAXN << 2];
int rev(int idx) {
  if (idx == n + 1) return 3 * n + 1;
  return idx;
}
int f(int idx) {
  if (idx == 3 * n + 1) return n + 1;
  return idx;
}
void build(int node, int st, int en) {
  ans[node] = rev(st);
  if (en - st < 2) return;
  int mid = (st + en) >> 1;
  build(node << 1, st, mid);
  build(node << 1 | 1, mid, en);
}
void upd(int node, int st, int en, int x) {
  mn[node] = mx[node] = x;
  ans[node] = x + rev(st);
  lazy[node] = x;
  return;
}
void shift(int node, int st, int en) {
  int mid = (st + en) >> 1;
  if (lazy[node] == 0) return;
  upd(node << 1, st, mid, lazy[node]);
  upd(node << 1 | 1, mid, en, lazy[node]);
  lazy[node] = 0;
}
void update(int node, int st, int en, int l, int r, int x) {
  if (l >= en || st >= r || mn[node] >= x) return;
  if (l <= st && en <= r && mx[node] <= x) {
    upd(node, st, en, x);
    return;
  }
  int mid = (st + en) >> 1;
  shift(node, st, en);
  update(node << 1, st, mid, l, r, x);
  update(node << 1 | 1, mid, en, l, r, x);
  mn[node] = min(mn[node << 1], mn[node << 1 | 1]);
  mx[node] = max(mx[node << 1], mx[node << 1 | 1]);
  ans[node] = min(ans[node << 1], ans[node << 1 | 1]);
}
bool cmp(int u, int v) { return fir[u] < fir[v]; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) cin >> c[i];
  vector<int> v;
  for (int i = 1; i <= n; i++)
    v.push_back(a[i]), v.push_back(b[i]), v.push_back(c[i]);
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  sz = v.size();
  for (int i = 1; i <= n; i++)
    a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
  for (int i = 1; i <= n; i++)
    b[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
  for (int i = 1; i <= n; i++)
    c[i] = lower_bound(v.begin(), v.end(), c[i]) - v.begin();
  for (int i = 0; i < sz; i++)
    fir[i] = 3 * n + 1, sec[i] = 3 * n + 1, thir[i] = 3 * n + 1;
  for (int i = n; i >= 1; i--) fir[a[i]] = i;
  for (int i = n; i >= 1; i--) sec[b[i]] = i;
  for (int i = n; i >= 1; i--) thir[c[i]] = i;
  v.clear();
  for (int i = 0; i < sz; i++) v.push_back(i);
  sort(v.begin(), v.end(), cmp);
  build(1, 0, n + 2);
  int cnt = fir[v.back()];
  for (int i = sz - 1; i >= 0; i--) {
    int idx = v[i], cur = 0;
    update(1, 0, n + 2, 0, f(sec[idx]), thir[idx]);
    if (i) cur = fir[v[i - 1]];
    cnt = min(cnt, ans[1] + cur);
  }
  cout << cnt;
}
