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 N = 1e5 + 5, inf = 1e9;
int n, a[N][3], first[N * 3][3], f[N];
vector<int> vec;
void compress() {
  for (int j = 0; j < 3; j++)
    for (int i = 0; i < n; i++) vec.push_back(a[i][j]);
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  for (int j = 0; j < 3; j++)
    for (int i = 0; i < n; i++)
      a[i][j] = lower_bound(vec.begin(), vec.end(), a[i][j]) - vec.begin();
}
struct node {
  int mx, mn, best, lazy;
  node() { lazy = -1; }
} seg[N << 2];
node merge(node x, node y) {
  node ret;
  ret.best = min(x.best, y.best);
  ret.mx = max(x.mx, y.mx);
  ret.mn = min(x.mn, y.mn);
  return ret;
}
void build(int id = 1, int b = 0, int e = n + 1) {
  if (e - b == 1) {
    seg[id].mx = seg[id].mn = f[b];
    seg[id].best = f[b] + b;
    return;
  }
  int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;
  build(lc, b, mid);
  build(rc, mid, e);
  seg[id] = merge(seg[lc], seg[rc]);
}
void shift(int id, int b, int e) {
  if (seg[id].lazy != -1) {
    int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;
    seg[lc].mx = max(seg[lc].mx, seg[id].lazy);
    seg[rc].mx = max(seg[rc].mx, seg[id].lazy);
    seg[lc].mn = max(seg[lc].mn, seg[id].lazy);
    seg[rc].mn = max(seg[rc].mn, seg[id].lazy);
    seg[lc].best = max(seg[lc].best, seg[id].lazy + b);
    seg[rc].best = max(seg[rc].best, seg[id].lazy + mid);
    seg[lc].lazy = max(seg[lc].lazy, seg[id].lazy);
    seg[rc].lazy = max(seg[rc].lazy, seg[id].lazy);
    seg[id].lazy = -1;
    return;
  }
}
void modify(int l, int r, int val, int id = 1, int b = 0, int e = n + 1) {
  if (l >= e || b >= r || seg[id].mn >= val) return;
  if (l <= b && e <= r && seg[id].mx < val) {
    seg[id].best = b + val;
    seg[id].mx = seg[id].mn = val;
    seg[id].lazy = max(seg[id].lazy, val);
    return;
  }
  int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;
  shift(id, b, e);
  modify(l, r, val, lc, b, mid);
  modify(l, r, val, rc, mid, e);
  seg[id] = merge(seg[lc], seg[rc]);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  memset(first, -1, sizeof first);
  for (int j = 0; j < 3; j++)
    for (int i = 0; i < n; i++) cin >> a[i][j];
  compress();
  for (int j = 0; j < 3; j++)
    for (int i = 0; i < n; i++)
      first[a[i][j]][j] = ((first[a[i][j]][j] == -1) ? i : first[a[i][j]][j]);
  set<int> s, total;
  for (int i = 0; i < n; i++)
    s.insert(first[a[i][2]][2]), total.insert(a[i][1]);
  for (int i = 0; i < n; i++)
    s.erase(first[a[i][0]][2]), total.erase(a[i][0]), total.erase(a[i][2]);
  for (int i = 0; i <= n; i++) {
    if (total.size())
      f[i] = inf;
    else {
      if (s.size())
        f[i] = (*s.rbegin()) + 1;
      else
        f[i] = 0;
    }
    s.erase(first[a[i][1]][2]), total.erase(a[i][1]);
  }
  build();
  int ans = 3 * n;
  for (int i = n - 1; ~i; i--) {
    ans = min(ans, seg[1].best + i + 1);
    if (first[a[i][0]][0] == i) {
      int x = first[a[i][0]][1], y = first[a[i][0]][2];
      if (x == -1) {
        if (y == -1)
          modify(0, n + 1, inf);
        else
          modify(0, n + 1, y + 1);
      } else {
        if (y == -1)
          modify(0, x + 1, inf);
        else
          modify(0, x + 1, y + 1);
      }
    }
  }
  ans = min(ans, seg[1].best);
  cout << ans << "\n";
}
