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 N;
int V[3][101000];
map<int, int> M;
int mi[3][303000];
set<pair<int, int> > P;
multiset<int> R;
void add(int bx, int cy) {
  int y;
  set<pair<int, int> >::iterator n = P.lower_bound(make_pair(bx, cy)), prev;
  if (n->second >= cy) return;
  y = n->second;
  R.insert(bx + y);
  prev = n;
  prev--;
  while (prev->second <= cy)
    R.erase(R.lower_bound(prev->first + y)), y = prev->second, P.erase(prev--);
  R.erase(R.lower_bound(prev->first + y));
  P.insert(make_pair(bx, cy));
  R.insert(prev->first + cy);
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  int debug = 0;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3 * N + 5; j++) mi[i][j] = 4 * N;
    for (j = 0; j < N; j++) {
      cin >> x;
      if (M.count(x) == 0) M[x] = M.size() - 1;
      mi[i][M[x]] = min(mi[i][M[x]], j + 1);
    }
  }
  int ans = mi[0][M.size() - 1];
  P.insert(make_pair(0, 9 * N + 1));
  P.insert(make_pair(9 * N + 1, 0));
  R.insert(9 * N + 1);
  for (i = M.size() - 1; i >= 0; i--) {
    ans = min(ans, mi[0][i] + *R.begin());
    add(mi[1][i], mi[2][i]);
  }
  ans = min(ans, *R.begin());
  cout << ans << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false);
  for (i = 0; i < argc - 1; i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
