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>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int nmax = 511222;
void read(int a[nmax], int n, int all[]) {
  for (int(i) = 0; (i) < (n); ++(i)) {
    scanf("%d", &a[i]);
    all[i] = a[i];
  }
}
void make_small(int a[nmax], int n, int all[nmax], int sz) {
  for (int(i) = 0; (i) < (n); ++(i)) {
    a[i] = lower_bound(all, all + sz, a[i]) - all;
  }
}
int a[nmax], b[nmax], c[nmax], all[nmax];
int pa[nmax], pb[nmax], pc[nmax];
int n, sz;
struct element {
  int a, b, c;
};
bool comp(element e1, element e2) { return e1.a < e2.a; }
element mas[nmax];
struct node {
  bool end;
  int val;
  int ans;
};
node T[nmax * 4];
int getval(int pos) {
  int v = 1;
  int l = 0;
  int r = n;
  while (T[v].end != true) {
    int mid = (l + r) / 2;
    if (pos <= mid) {
      r = mid;
      v = v * 2;
    } else {
      l = mid + 1;
      v = v * 2 + 1;
    }
  }
  return T[v].val;
}
void update(int v, int l, int r, int kl, int kr, int val) {
  if (l == kl && r == kr) {
    T[v].end = true;
    assert(val >= T[v].val);
    T[v].val = val;
    T[v].ans = val + l;
    return;
  } else {
    int mid = (l + r) / 2;
    if (T[v].end) {
      T[v * 2].val = T[v].val;
      T[v * 2].end = true;
      T[v * 2].ans = T[v].ans;
      T[v * 2 + 1].val = T[v].val;
      T[v * 2 + 1].end = true;
      T[v * 2 + 1].ans = T[v].val + mid + 1;
      T[v].end = false;
    }
    if (kr <= mid) update(v * 2, l, mid, kl, kr, val);
    if (kl > mid) update(v * 2 + 1, mid + 1, r, kl, kr, val);
    if (kl <= mid && kr > mid) {
      update(v * 2, l, mid, kl, mid, val);
      update(v * 2 + 1, mid + 1, r, mid + 1, kr, val);
    }
    T[v].ans = min(T[v * 2].ans, T[v * 2 + 1].ans);
  }
}
int main() {
  scanf("%d", &n);
  read(a, n, all);
  read(b, n, all + n);
  read(c, n, all + n + n);
  sort(all, all + 3 * n);
  int sall = 1;
  for (int(i) = (1); (i) <= (3 * n - 1); ++(i)) {
    if (all[i] != all[i - 1]) all[sall++] = all[i];
  }
  make_small(a, n, all, sall);
  make_small(b, n, all, sall);
  make_small(c, n, all, sall);
  sz = sall;
  for (int(i) = 0; (i) < (sz); ++(i)) pa[i] = pb[i] = pc[i] = 1000000000;
  for (int(i) = (n); (i)--;) {
    pa[a[i]] = i;
    pb[b[i]] = i;
    pc[c[i]] = i;
  }
  for (int(i) = 0; (i) < (sz); ++(i)) {
    mas[i].a = pa[i];
    mas[i].b = pb[i];
    mas[i].c = pc[i];
  }
  sort(mas, mas + sz, comp);
  int ans = n + n + n;
  if (mas[sz - 1].a != 1000000000) ans = mas[sz - 1].a + 1;
  T[1].end = true;
  for (int(i) = (sz); (i)--;) {
    element cur = mas[i];
    if (cur.b == 1000000000) cur.b = n;
    if (getval(cur.b) < cur.c + 1) {
      int l = -1, r = cur.b;
      while (l < r - 1) {
        int mid = (l + r) / 2;
        if (getval(mid) < cur.c + 1)
          r = mid;
        else
          l = mid;
      }
      update(1, 0, n, r, cur.b, cur.c + 1);
    }
    ans = min(ans, (i == 0 ? 0 : mas[i - 1].a + 1) + T[1].ans);
  }
  cout << ans << endl;
  return 0;
}
