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 inf = 500000000;
const int N = 100100;
struct dui {
  int x, id;
} a[3 * N];
int b[N], c[N], d[N], e[N], f[N], q[N], to[N], g[N], t[N], n, top, mn[4 * N],
    tag[4 * N];
bool cmp(dui x, dui y) { return x.x < y.x; }
void ycl() {
  int i, j, k;
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) {
    if (!t[b[i]]) e[i] = 1;
    t[b[i]]++;
  }
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) {
    if (!t[c[i]]) f[c[i]] = i;
    t[c[i]]++;
  }
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) {
    if (!t[d[i]]) g[d[i]] = i;
    t[d[i]]++;
  }
}
void upd(int rt) { mn[rt] = min(mn[rt << 1], mn[rt << 1 | 1]); }
void push(int l, int mid, int r, int rt) {
  if (tag[rt]) {
    tag[rt << 1] = max(tag[rt << 1], tag[rt]);
    tag[rt << 1 | 1] = max(tag[rt << 1 | 1], tag[rt]);
    mn[rt << 1] = max(mn[rt << 1], l + tag[rt]);
    mn[rt << 1 | 1] = max(mn[rt << 1 | 1], mid + 1 + tag[rt]);
    tag[rt] = 0;
  }
}
void build(int l, int r, int rt) {
  if (l == r) {
    mn[rt] = l + to[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  upd(rt);
}
void cg(int l, int r, int rt, int cl, int cr, int vl) {
  if ((cl > n) || (cr > n) || (cl > cr)) return;
  if ((cl <= l) && (r <= cr)) {
    tag[rt] = max(tag[rt], vl);
    mn[rt] = max(mn[rt], l + vl);
    return;
  }
  int mid = (l + r) >> 1;
  push(l, mid, r, rt);
  if (cl <= mid) cg(l, mid, rt << 1, cl, cr, vl);
  if (cr > mid) cg(mid + 1, r, rt << 1 | 1, cl, cr, vl);
  upd(rt);
}
int main() {
  int i, j, k, ans, top, cnt, p, m, l, r;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i].x);
    a[i].id = i;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[n + i].x);
    a[n + i].id = n + i;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[n + n + i].x);
    a[n + n + i].id = n + n + i;
  }
  sort(a + 1, a + 3 * n + 1, cmp);
  top = 0;
  for (i = 1; i <= 3 * n; i++) {
    if (a[i].x != a[i - 1].x) top++;
    if (a[i].id <= n)
      b[a[i].id] = top;
    else if (a[i].id <= 2 * n)
      c[a[i].id - n] = top;
    else
      d[a[i].id - n - n] = top;
  }
  for (i = 1; i <= n; i++) t[b[i]]++;
  for (i = 1; i <= n; i++) t[c[i]]++;
  cnt = 0;
  for (i = 1; i <= top; i++)
    if (!t[i]) cnt++;
  p = 0;
  while (cnt) {
    p++;
    t[d[p]]++;
    if (t[d[p]] == 1) cnt--;
  }
  to[n] = p;
  for (i = n; i; i--) {
    t[c[i]]--;
    if (!t[c[i]])
      while ((p < n) && (d[p] != c[i])) t[d[++p]]++;
    if ((p == n) && (d[p] != c[i])) break;
    to[i - 1] = p;
  }
  for (i--; i >= 0; i--) to[i] = inf;
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) t[b[i]]++;
  for (i = 1; i <= n; i++) t[d[i]]++;
  cnt = 0;
  for (i = 1; i <= top; i++)
    if (!t[i]) cnt++;
  p = 0;
  while (cnt) {
    p++;
    t[c[p]]++;
    if (t[c[p]] == 1) cnt--;
  }
  q[n] = cnt;
  for (i = n; i; i--) {
    t[d[i]]--;
    if (!t[d[i]])
      while ((p < n) && (c[p] != d[i])) t[c[++p]]++;
    if ((p == n) && (c[p] != d[i])) break;
    q[i - 1] = p;
  }
  for (i--; i >= 0; i--) q[i] = inf;
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) t[c[i]]++;
  for (i = 1; i <= n; i++) t[d[i]]++;
  for (m = n; m >= 0; m--)
    if (!t[b[m]]) break;
  build(0, n, 1);
  ycl();
  ans = n + mn[1];
  for (i = n; i > m; i--) {
    if (!f[b[i]])
      r = n;
    else
      r = f[b[i]] - 1;
    if ((e[i]) && (g[b[i]])) {
      l = q[g[b[i]] - 1];
      cg(0, n, 1, l, r, g[b[i]]);
    } else if ((e[i]) && (!g[b[i]]))
      cg(0, n, 1, 0, r, inf);
    ans = min(ans, i - 1 + mn[1]);
  }
  printf("%d\n", ans);
  return 0;
}
