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 maxn = 1e5 + 5, inf = 3e5 + 5;
unordered_map<int, int> MA, MB, MC;
int a[maxn], b[maxn], c[maxn], mn[4 * maxn], mx[4 * maxn], seg[4 * maxn],
    lazy[4 * maxn];
void build(int id, int L, int R) {
  if (R == L + 1) {
    seg[id] = L;
    return;
  }
  int mid = (L + R) / 2;
  build(2 * id + 0, L, mid);
  build(2 * id + 1, mid, R);
  seg[id] = L;
}
void relax(int id, int L, int mid) {
  int x = lazy[id];
  lazy[id] = -1;
  if (~x) {
    mn[2 * id + 0] = x;
    mn[2 * id + 1] = x;
    mx[2 * id + 0] = x;
    mx[2 * id + 1] = x;
    seg[2 * id + 0] = x + L;
    seg[2 * id + 1] = x + mid;
    lazy[2 * id + 0] = x;
    lazy[2 * id + 1] = x;
  }
}
void add(int id, int L, int R, int l, int r, int x) {
  if (R <= l || r <= L || mn[id] >= x) return;
  if (L >= l && R <= r && mn[id] == mx[id]) {
    mn[id] = x;
    mx[id] = x;
    seg[id] = x + L;
    lazy[id] = x;
    return;
  }
  int mid = (L + R) / 2;
  relax(id, L, mid);
  add(2 * id + 0, L, mid, l, r, x);
  add(2 * id + 1, mid, R, l, r, x);
  mn[id] = min(mn[2 * id + 0], mn[2 * id + 1]);
  mx[id] = max(mx[2 * id + 0], mx[2 * id + 1]);
  seg[id] = min(seg[2 * id + 0], seg[2 * id + 1]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  fill(lazy, lazy + 4 * maxn, -1);
  build(1, 0, n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    MA[a[i]] = i;
    MB[b[i]] = i;
    MC[c[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    if (MA.find(b[i]) == MA.end() && MB[b[i]] == i) {
      if (MC.find(b[i]) != MC.end())
        add(1, 0, n + 1, 0, i + 1, MC[b[i]] + 1);
      else
        add(1, 0, n + 1, 0, i + 1, inf);
    }
  }
  for (int i = 0; i < n; i++) {
    if (MA.find(c[i]) == MA.end() && MB.find(c[i]) == MB.end() &&
        MC[c[i]] == i) {
      add(1, 0, n + 1, 0, n + 1, i + 1);
    }
  }
  int ans = 3 * n;
  ans = min(ans, seg[1] + n);
  for (int i = n - 1; i >= 0; i--) {
    if (MA[a[i]] == i && MB.find(a[i]) != MB.end()) {
      if (MC.find(a[i]) != MC.end())
        add(1, 0, n + 1, 0, MB[a[i]] + 1, MC[a[i]] + 1);
      else
        add(1, 0, n + 1, 0, MB[a[i]] + 1, inf);
    } else if (MA[a[i]] == i) {
      if (MC.find(a[i]) != MC.end())
        add(1, 0, n + 1, 0, n + 1, MC[a[i]] + 1);
      else
        add(1, 0, n + 1, 0, n + 1, inf);
    }
    ans = min(ans, seg[1] + i);
  }
  cout << ans;
}
