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>
const int maxn = 100005;
struct Mnum {
  int x, typ, id;
  void input(int _x, int _typ, int _id) {
    x = _x;
    typ = _typ;
    id = _id;
  }
  bool operator<(const Mnum b) const {
    if (x != b.x) return x < b.x;
    return id < b.id;
  }
} num[maxn * 3];
int arr[3][maxn];
int loc[3][maxn * 3];
int fla[maxn * 3];
int n, m, maxnum;
inline int cal_max(int x, int y) {
  if (x > y) return x;
  return y;
}
inline int cal_min(int x, int y) {
  if (x < y) return x;
  return y;
}
struct SEG {
  int seg_max[maxn << 2];
  int seg_min[maxn << 2];
  int laz[maxn << 2];
  int res[maxn << 2];
  inline int lchi(int rt) { return rt << 1; }
  inline int rchi(int rt) { return (rt << 1) + 1; }
  void init(int rt, int l, int r) {
    laz[rt] = 0;
    res[rt] = 0;
    seg_max[rt] = seg_min[rt] = 0;
  }
  void pushdown(int rt, int l, int r) {
    if (laz[rt] == -1) return;
    seg_max[lchi(rt)] = seg_max[rt];
    seg_min[lchi(rt)] = seg_min[rt];
    seg_max[rchi(rt)] = seg_max[rt];
    seg_min[rchi(rt)] = seg_min[rt];
    laz[lchi(rt)] = laz[rchi(rt)] = laz[rt];
    res[lchi(rt)] = seg_min[rt] + l;
    res[rchi(rt)] = seg_min[rt] + ((l + r) >> 1) + 1;
    laz[rt] = -1;
  }
  void pushup(int rt, int l, int r) {
    seg_max[rt] = cal_max(seg_max[lchi(rt)], seg_max[rchi(rt)]);
    seg_min[rt] = cal_min(seg_min[lchi(rt)], seg_min[rchi(rt)]);
    res[rt] = cal_min(res[lchi(rt)], res[rchi(rt)]);
  }
  void update(int rt, int l, int r, int L, int R, int tem) {
    int mid = (l + r) >> 1;
    if (tem <= seg_min[rt]) return;
    if (L <= l && r <= R) {
      if (tem >= seg_max[rt]) {
        seg_max[rt] = seg_min[rt] = laz[rt] = tem;
        res[rt] = l + laz[rt];
        return;
      }
    }
    pushdown(rt, l, r);
    if (mid >= L) update(lchi(rt), l, mid, L, R, tem);
    if (mid < R) update(rchi(rt), mid + 1, r, L, R, tem);
    pushup(rt, l, r);
  }
  int query(int rt, int l, int r, int L, int R) {
    int mid = (l + r) >> 1;
    int ans = -1, tem;
    if (L <= l && r <= R) return res[rt];
    pushdown(rt, l, r);
    if (mid >= L) {
      tem = query(lchi(rt), l, mid, L, R);
      if (ans == -1 || ans > tem) ans = tem;
    }
    if (mid < R) {
      tem = query(rchi(rt), mid + 1, r, L, R);
      if (ans == -1 || ans > tem) ans = tem;
    }
    pushup(rt, l, r);
    return ans;
  }
} seg;
void debug() {
  int i;
  for (i = 0; i < m; i++) printf("%3d", fla[i]);
  printf("\n\n");
  for (i = 1; i <= n; i++) printf("%3d", arr[0][i]);
  printf("\n");
  for (i = 1; i <= n; i++) printf("%3d", arr[1][i]);
  printf("\n");
  for (i = 1; i <= n; i++) printf("%3d", arr[2][i]);
  printf("\n");
  printf("\n");
  for (i = 1; i <= maxnum; i++) printf("%3d", loc[0][i]);
  printf("\n");
  for (i = 1; i <= maxnum; i++) printf("%3d", loc[1][i]);
  printf("\n");
  for (i = 1; i <= maxnum; i++) printf("%3d", loc[2][i]);
  printf("\n");
}
int main() {
  int i, j, k, ans, tem;
  int u, v, w;
  scanf("%d", &n);
  for (i = 1, j = 0; i <= n; i++, j++) {
    scanf("%d", &arr[0][i]);
    num[j].input(arr[0][i], 0, i);
  }
  for (i = 1; i <= n; i++, j++) {
    scanf("%d", &arr[1][i]);
    num[j].input(arr[1][i], 1, i);
  }
  for (i = 1; i <= n; i++, j++) {
    scanf("%d", &arr[2][i]);
    num[j].input(arr[2][i], 2, i);
  }
  m = j;
  std::sort(num, num + m);
  memset(loc, -1, sizeof(loc));
  i = 0;
  fla[i] = 1;
  if (loc[num[i].typ][fla[i]] == -1) {
    loc[num[i].typ][fla[i]] = num[i].id;
    arr[num[i].typ][num[i].id] = fla[i];
  } else
    arr[num[i].typ][num[i].id] = 0;
  for (i = 1; i < m; i++) {
    fla[i] = fla[i - 1] + (num[i].x != num[i - 1].x);
    if (loc[num[i].typ][fla[i]] == -1) {
      loc[num[i].typ][fla[i]] = num[i].id;
      arr[num[i].typ][num[i].id] = fla[i];
    } else
      arr[num[i].typ][num[i].id] = 0;
  }
  maxnum = fla[m - 1];
  u = 0;
  v = 0;
  w = 0;
  for (i = 1; i <= maxnum; i++)
    if (loc[1][i] == -1 && loc[2][i] == -1 && u < loc[0][i]) u = loc[0][i];
  for (i = 1; i <= maxnum; i++)
    if (loc[0][i] == -1 && loc[2][i] == -1 && v < loc[1][i]) v = loc[1][i];
  for (i = 1; i <= maxnum; i++)
    if (loc[0][i] == -1 && loc[1][i] == -1 && w < loc[0][i]) w = loc[2][i];
  i = n;
  seg.init(1, 0, n);
  seg.update(1, 0, n, 0, n, w);
  for (j = v + 1; j <= n; j++)
    if (arr[1][j] > 0 && loc[0][arr[1][j]] == -1)
      seg.update(1, 0, n, 0, j - 1, loc[2][arr[1][j]]);
  ans = n + seg.query(1, 0, n, v, n);
  for (i--; i >= u; i--) {
    tem = arr[0][i + 1];
    if (tem > 0) {
      if (loc[1][tem] == -1) {
        if (w < loc[2][tem]) {
          w = loc[2][tem];
          seg.update(1, 0, n, 0, n, w);
        }
      } else {
        if (loc[2][tem] == -1) {
          if (v < loc[1][tem]) v = loc[1][tem];
        } else
          seg.update(1, 0, n, 0, loc[1][tem] - 1, loc[2][tem]);
      }
    }
    tem = i + seg.query(1, 0, n, v, n);
    if (ans > tem) ans = tem;
  }
  printf("%d\n", ans);
  return 0;
}
