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 = 2e5 + 5, M = 4e5 + 5, inf = 1e8;
void mx(int& a, int b) {
  if (a < b) a = b;
}
int LZ[N << 2], A[3][N], ll[3][M], B[N], T[M], pt, n, m, t, rt;
vector<int> v;
struct node {
  int mn, mx, rt;
} D[N << 2];
node merg(const node& a, const node& b) {
  node rt;
  rt.mx = max(a.mx, b.mx);
  rt.mn = min(a.mn, b.mn);
  rt.rt = min(a.rt, b.rt);
  return (rt);
}
void build(int id = 1, int l = 0, int r = n) {
  if (r - l < 2) {
    D[id].rt = D[id].mn = D[id].mx = B[l];
    D[id].rt += l;
    return;
  }
  int mid = ((l + r) >> 1);
  build((id << 1), l, mid);
  build((id << 1 | 1), mid, r);
  D[id] = merg(D[(id << 1)], D[(id << 1 | 1)]);
}
void ad(int id, int d) {
  D[id].mx += d;
  D[id].mn += d;
  D[id].rt += d;
  LZ[id] += d;
}
void shift(int id, int l, int r) {
  ad((id << 1), LZ[id]);
  ad((id << 1 | 1), LZ[id]);
  LZ[id] = 0;
}
void add(int s, int e, int d, int id = 1, int l = 0, int r = n) {
  if (l >= e || r <= s) return;
  if (D[id].mn > d) return;
  if (l >= s && r <= e && D[id].mn == D[id].mx) {
    ad(id, d - D[id].mn);
    return;
  }
  int mid = ((l + r) >> 1);
  shift(id, l, r);
  add(s, e, d, (id << 1), l, mid);
  add(s, e, d, (id << 1 | 1), mid, r);
  D[id] = merg(D[(id << 1)], D[(id << 1 | 1)]);
}
int main() {
  scanf("%d", &n);
  m = n + n + n + 1;
  rt = m - 1;
  n++;
  for (int i = 0; i < 3; i++)
    for (int j = 1; j < n; j++) {
      scanf("%d", &A[i][j]);
      v.push_back(A[i][j]);
    }
  set<int> st(v.begin(), v.end());
  v.assign(st.begin(), st.end());
  t = (int)v.size();
  for (int i = 0; i < 3; i++)
    for (int j = 1; j < n; j++) {
      A[i][j] = lower_bound(v.begin(), v.end(), A[i][j]) - v.begin();
    }
  for (int i = 0; i < 3; i++) fill(ll[i], ll[i] + M, n);
  for (int i = 0; i < 3; i++)
    for (int j = n - 1; j; j--) ll[i][A[i][j]] = j;
  for (int i = 0; i < 3; i++)
    for (int j = 1; j < n; j++) T[A[i][j]]++;
  int pt = n - 1;
  for (int i = n - 1; ~i; i--) {
    while (pt && T[A[2][pt]] > 1) {
      T[A[2][pt]]--;
      pt--;
    }
    B[i] = pt;
    if (!i) break;
    T[A[1][i]]--;
    while (!T[A[1][i]] && pt + 1 < n) {
      pt++;
      T[A[2][pt]]++;
    }
    if (!T[A[1][i]]) {
      for (int j = i - 1; j >= 0; j--) B[j] = inf;
      break;
    }
  }
  build();
  for (int i = n - 1; ~i; i--) {
    rt = min(rt, D[1].rt + i);
    if (!i) break;
    int a = A[0][i];
    if (ll[0][a] ^ i) continue;
    if (ll[1][a] == n && ll[2][a] == n) break;
    add(0, ll[1][a], ll[2][a] == n ? inf : ll[2][a]);
  }
  printf("%d", rt);
}
