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;
template <class T>
bool setmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  } else
    return false;
}
template <class T>
bool setmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  } else
    return false;
}
struct data {
  int pa, pb, pc;
};
std::vector<data> da;
int constexpr inf = 1 << 28;
int constexpr maxn = 300007;
int a[maxn], b[maxn], c[maxn];
int n, endpos;
std::multiset<int> act;
using pair_type = std::pair<int, int>;
bool operator<(pair_type const &a, pair_type const &b) {
  return a.first < b.first;
}
std::set<pair_type> points;
void erase(pair_type p) {
  auto y = points.lower_bound(p);
  auto x = y;
  auto z = y;
  --x, ++z;
  act.erase(act.find(x->first + y->second));
  act.erase(act.find(y->first + z->second));
  act.insert(x->first + z->second);
  points.erase(y);
}
void insert(pair_type p) {
  points.insert(p);
  auto y = points.lower_bound(p);
  auto x = y;
  auto z = y;
  --x, ++z;
  if (z->second > y->second) {
    points.erase(p);
    return;
  }
  act.insert(x->first + y->second);
  act.insert(y->first + z->second);
  act.erase(act.find(x->first + z->second));
  while (1) {
    x = points.lower_bound(p);
    --x;
    if (x->second < p.second) {
      erase(*x);
    } else
      break;
  }
}
int const MAXN = maxn;
struct Tri {
  int i, j, k;
  bool operator<(const Tri &t) const { return k < t.k; }
} d[MAXN];
void init() {
  static int a[MAXN], b[MAXN], c[MAXN];
  cin >> n;
  for (int i = (int)(1); i <= (int)(n); ++i) cin >> a[i];
  for (int i = (int)(1); i <= (int)(n); ++i) cin >> b[i];
  for (int i = (int)(1); i <= (int)(n); ++i) cin >> c[i];
  map<int, int> pa, pb, pc;
  set<int> numbers;
  for (int i = (int)(n); i >= (int)(1); --i) numbers.insert(a[i]), pa[a[i]] = i;
  for (int i = (int)(n); i >= (int)(1); --i) numbers.insert(b[i]), pb[b[i]] = i;
  for (int i = (int)(n); i >= (int)(1); --i) numbers.insert(c[i]), pc[c[i]] = i;
  n = 0;
  int tt = endpos = MAXN * 3;
  for (set<int>::iterator it = numbers.begin(); it != numbers.end(); ++it) {
    int x = *it;
    ++n;
    if (pa.find(x) == pa.end())
      d[n].i = ++tt;
    else
      d[n].i = pa[x];
    if (pb.find(x) == pb.end())
      d[n].j = ++tt;
    else
      d[n].j = pb[x];
    if (pc.find(x) == pc.end())
      d[n].k = ++tt;
    else
      d[n].k = pc[x];
  }
}
void solve() {
  std::sort(d + 1, d + n + 1);
  int ret = 1 << 30;
  points.clear();
  points.insert(pair_type(0, inf));
  points.insert(pair_type(inf, 0));
  act.insert(0);
  int cur = n;
  while (cur >= 1 && d[cur].k >= endpos) {
    insert(pair_type(d[cur].i, d[cur].j));
    --cur;
  }
  while (cur >= 1) {
    ret = std::min(ret, *act.begin() + d[cur].k);
    insert(pair_type(d[cur].i, d[cur].j));
    --cur;
  }
  ret = std::min(ret, *act.begin());
  std::cout << ret << std::endl;
}
int main() {
  init();
  solve();
}
