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;
int i, j, k, n, m, x, y, z, a[(int)(1e5 + 10)], b[(int)(1e5 + 10)],
    c[(int)(1e5 + 10)];
int L[4 * (int)(1e5 + 10)], St[4 * (int)(1e5 + 10)], aa[4 * (int)(1e5 + 10)],
    bb[4 * (int)(1e5 + 10)];
pair<int, pair<int, int> > A[3 * (int)(1e5 + 10)];
map<int, int> H;
vector<int> v;
void push(int root) {
  if (L[root]) {
    bb[(root << 1)] = bb[((root << 1) | 1)] = L[(root << 1)] =
        L[((root << 1) | 1)] = L[root];
    St[((root << 1) | 1)] = L[root] + aa[((root << 1) | 1)];
    St[(root << 1)] = L[root] + aa[(root << 1)];
    L[root] = 0;
  }
}
int que(int root, int bas, int son, int x) {
  if (bas > x or son < x) return 0;
  if (bas == son) return bb[root];
  push(root);
  return que((root << 1), bas, ((bas + son) >> 1), x) +
         que(((root << 1) | 1), ((bas + son) >> 1) + 1, son, x);
}
int upd2(int root, int bas, int son, int x, int y, int t) {
  if (bas > y or son < x) return St[root];
  if (x <= bas and son <= y) {
    L[root] = bb[root] = t;
    return St[root] = t + aa[root];
  }
  push(root);
  upd2((root << 1), bas, ((bas + son) >> 1), x, y, t);
  upd2(((root << 1) | 1), ((bas + son) >> 1) + 1, son, x, y, t);
  bb[root] = max(bb[(root << 1)], bb[((root << 1) | 1)]);
  St[root] = min(St[(root << 1)], St[((root << 1) | 1)]);
}
int upd1(int root, int bas, int son, int x) {
  if (bas > x or son < x) return St[root];
  if (bas == son) {
    aa[root] = x;
    return St[root] = x + bb[root];
  }
  push(root);
  upd1((root << 1), bas, ((bas + son) >> 1), x);
  upd1(((root << 1) | 1), ((bas + son) >> 1) + 1, son, x);
  aa[root] = min(aa[(root << 1)], aa[((root << 1) | 1)]);
  St[root] = min(St[(root << 1)], St[((root << 1) | 1)]);
}
void init(int root, int bas, int son) {
  if (bas == son) {
    aa[root] = St[root] = 1000000007;
    bb[root] = L[root] = 0;
    return;
  }
  init((root << 1), bas, ((bas + son) >> 1));
  init(((root << 1) | 1), ((bas + son) >> 1) + 1, son);
  aa[root] = 1000000007;
  St[root] = 1000000007;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%d", a + i);
    v.push_back(a[i]);
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", b + i);
    v.push_back(b[i]);
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", c + i);
    v.push_back(c[i]);
  }
  sort(v.begin(), v.end());
  int s = 1;
  H[v[0]] = 1;
  for (i = 1; i < v.size(); i++)
    if (v[i - 1] != v[i]) H[v[i]] = ++s;
  memset(A, 5, sizeof A);
  for (i = 1; i <= n; i++) A[H[a[i]]].first = min(A[H[a[i]]].first, i);
  for (i = 1; i <= n; i++)
    A[H[b[i]]].second.first = min(A[H[b[i]]].second.first, i);
  for (i = 1; i <= n; i++)
    A[H[c[i]]].second.second = min(A[H[c[i]]].second.second, i);
  sort(A + 1, A + 1 + s);
  init(1, 0, n);
  int ans = A[s].first;
  for (i = s; i >= 1; i--) {
    if (A[i].second.first <= n) upd1(1, 0, n, A[i].second.first);
    int bas = 0;
    int son = min(A[i].second.first - 1, n);
    while (bas < son) {
      if (que(1, 0, n, ((bas + son) >> 1)) > A[i].second.second)
        bas = ((bas + son) >> 1) + 1;
      else
        son = ((bas + son) >> 1);
    }
    if (que(1, 0, n, bas) <= A[i].second.second) {
      upd2(1, 0, n, bas, min(n, A[i].second.first - 1), A[i].second.second);
    }
    ans = min(ans, St[1] + A[i - 1].first);
    ans = min(ans, bb[1] + A[i - 1].first);
  }
  cout << ans << '\n';
}
