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 maxn = 100001;
const int inf = maxn * 10;
int a[maxn], b[maxn], c[maxn];
int n, listsa[maxn], listsb[maxn], listsc[maxn];
int posa[maxn], posb[maxn], posc[maxn];
int temp;
multiset<int> q;
set<pair<int, int> > tree;
int maxx, maxy;
void add(int x, int y) {
  pair<int, int> tem;
  maxx = max(maxx, x);
  maxy = max(maxy, y);
  tem = pair<int, int>(x, y);
  set<pair<int, int> >::iterator s1, sit, s2;
  if (tree.size() == 0) {
    tree.insert(tem);
  } else {
    sit = tree.upper_bound(tem);
    if (sit->first >= tem.first && sit->second >= tem.second) return;
    int aa;
    tree.insert(tem);
    sit = tree.find(tem);
    s1 = s2 = sit;
    s2++;
    if (s1 == tree.begin()) {
      aa = s1->first + s2->second;
      q.insert(aa);
    } else if (s2 == tree.end()) {
      s1--;
      aa = s1->first + sit->second;
      q.insert(aa);
    } else {
      s1--;
      aa = s1->first + s2->second;
      q.erase(aa);
      aa = s1->first + sit->second;
      q.insert(aa);
      aa = s2->second + sit->first;
      q.insert(aa);
    }
    sit = tree.find(tem);
    while (sit != tree.begin()) {
      s1 = sit;
      s1--;
      if (s1->first <= sit->first && s1->second <= sit->second) {
        if (s1 == tree.begin()) {
          aa = sit->second + s1->first;
          q.erase(aa);
          tree.erase(s1);
        } else {
          s2 = s1;
          s2--;
          aa = s2->first + s1->second;
          q.erase(aa);
          aa = s1->first + sit->second;
          q.erase(aa);
          aa = s2->first + sit->second;
          q.insert(aa);
          tree.erase(s1);
        }
      } else
        break;
      sit = tree.find(tem);
    }
  }
  if (tree.size() == 0)
    temp = inf;
  else if (q.size() == 0)
    temp = min(maxx, maxy);
  else
    temp = min(*q.begin(), min(maxx, maxy));
}
int main() {
  scanf("%d", &n);
  temp = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  map<int, int> exist, exista, existb, existc;
  int cnt = 0, cnta = 0, cntb = 0, cntc = 0;
  for (int i = 1; i <= n; i++) {
    if (exist[a[i]] == 0) exist[a[i]] = ++cnt;
    if (exist[b[i]] == 0) exist[b[i]] = ++cnt;
    if (exist[c[i]] == 0) exist[c[i]] = ++cnt;
  }
  for (int i = 1; i <= cnt; i++) posa[i] = posb[i] = posc[i] = inf;
  for (int i = 1; i <= n; i++) {
    if (exista[a[i]] == 0) exista[a[i]] = 1, posa[exist[a[i]]] = i;
    if (existb[b[i]] == 0) existb[b[i]] = 1, posb[exist[b[i]]] = i;
    if (existc[c[i]] == 0) existc[c[i]] = 1, posc[exist[c[i]]] = i;
  }
  for (int i = 1; i <= cnt; i++)
    if (posa[i] == inf) {
      add(posb[i], posc[i]);
    }
  int ans = inf;
  for (int len_a = n; len_a >= 0; len_a--) {
    ans = min(ans, len_a + temp);
    int ps = exist[a[len_a]];
    if (len_a && (posa[ps] == len_a)) {
      if (posb[ps] == inf && posc[ps] == inf) break;
      add(posb[ps], posc[ps]);
    }
  }
  cout << ans << endl;
  fclose(stdin);
  return 0;
}
