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 inf = 1e9;
const int N = 3000000;
struct T {
  int a, b, c;
  T(){};
  T(int a, int b, int c) : a(a), b(b), c(c){};
  bool operator<(const T &x) const {
    return ((a < x.a) || ((a == x.a) && (b < x.b)) ||
            ((a == x.a) && (b == x.b) && (c < x.c)));
  }
};
int n, a[N], b[N], c[N], t_min[4 * N], t_res[4 * N], t_upd[4 * N], k;
T x[N];
pair<int, int> p[N];
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t_min[v] = 0;
    t_res[v] = tl;
    t_upd[v] = 0;
    return;
  }
  int tm = (tl + tr) / 2;
  build(v * 2, tl, tm);
  build(v * 2 + 1, tm + 1, tr);
  t_min[v] = 0;
  t_res[v] = tl;
  t_upd[v] = 0;
}
void push(int v, int tl, int tr) {
  int tm = (tl + tr) / 2;
  if (t_upd[v] != 0) {
    t_min[v * 2] = t_upd[v];
    t_min[v * 2 + 1] = t_upd[v];
    t_res[v * 2] = min(inf, tl + t_upd[v]);
    t_res[v * 2 + 1] = min(inf, tm + 1 + t_upd[v]);
    t_upd[v * 2] = t_upd[v];
    t_upd[v * 2 + 1] = t_upd[v];
    t_upd[v] = 0;
  }
}
int get(int v, int tl, int tr, int val) {
  if (tl == tr) return tl;
  push(v, tl, tr);
  int tm = (tl + tr) / 2;
  if (t_min[v * 2] <= val)
    return get(v * 2, tl, tm, val);
  else
    return get(v * 2 + 1, tm + 1, tr, val);
}
void update(int v, int tl, int tr, int l, int r, int val) {
  if (l > r) return;
  if (l == tl && r == tr) {
    t_min[v] = val;
    t_res[v] = val + l;
    t_upd[v] = val;
    return;
  }
  push(v, tl, tr);
  int tm = (tl + tr) / 2;
  update(v * 2, tl, tm, l, min(r, tm), val);
  update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
  t_min[v] = min(t_min[v * 2], t_min[v * 2 + 1]);
  t_res[v] = min(t_res[v * 2], t_res[v * 2 + 1]);
}
int Min(int v, int tl, int tr, int l, int r) {
  if (l > r) return inf;
  if (l == tl && r == tr) return t_res[v];
  push(v, tl, tr);
  int tm = (tl + tr) / 2;
  return min(Min(v * 2, tl, tm, l, min(r, tm)),
             Min(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i <= n; i++) p[i].first = a[i];
  for (int i = 1; i <= n; i++) p[i + n].first = b[i];
  for (int i = 1; i <= n; i++) p[i + 2 * n].first = c[i];
  for (int i = 1; i <= 3 * n; i++) p[i].second = i;
  sort(p + 1, p + 3 * n + 1);
  k = 1;
  for (int i = 1; i <= 3 * n; i++) {
    if ((i > 1) && (p[i].first != p[i - 1].first)) k++;
    if (p[i].second <= n)
      a[p[i].second] = k;
    else if (p[i].second <= 2 * n)
      b[p[i].second - n] = k;
    else
      c[p[i].second - 2 * n] = k;
  }
  for (int i = 1; i <= k; i++) x[i] = T(inf, inf, inf);
  for (int i = 1; i <= n; i++) {
    x[a[i]].a = min(x[a[i]].a, i);
    x[b[i]].b = min(x[b[i]].b, i);
    x[c[i]].c = min(x[c[i]].c, i);
  }
  sort(x + 1, x + k + 1);
  int ans = 3 * n;
  build(1, 0, 3 * n);
  for (int i = k; i >= 0; i--) {
    if (x[i].a != inf) ans = min(ans, x[i].a + Min(1, 0, 3 * n, 0, 3 * n));
    if (!i) break;
    int j = get(1, 0, 3 * n, x[i].c);
    if (j < x[i].b) update(1, 0, 3 * n, j, min(3 * n, x[i].b - 1), x[i].c);
  }
  cout << ans;
  return 0;
}
