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 = 1e5 + 10, mod = 1e9 + 7, inf = 1e9;
map<int, int> mp[3];
vector<int> vec[maxn];
set<pair<int, int> > st;
int lim[3], a[maxn], val[4 * maxn], lz[4 * maxn], n, N;
void build(int l = 0, int r = N, int id = 1) {
  if (r - l == 1) {
    val[id] = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, 2 * id);
  build(mid, r, 2 * id + 1);
  val[id] = min(val[2 * id], val[2 * id + 1]);
}
void get(int l, int r, int id) {
  val[id] += lz[id];
  if (r - l > 1) {
    lz[2 * id] += lz[id];
    lz[2 * id + 1] += lz[id];
  }
  lz[id] = 0;
}
void Add(int f, int s, int x, int l = 0, int r = N, int id = 1) {
  if (f >= s || l >= r) return;
  get(l, r, id);
  if (s <= l || r <= f) return;
  if (f <= l && r <= s) {
    lz[id] += x;
    get(l, r, id);
    return;
  }
  int mid = (l + r) >> 1;
  Add(f, s, x, l, mid, 2 * id);
  Add(f, s, x, mid, r, 2 * id + 1);
  val[id] = min(val[2 * id], val[2 * id + 1]);
}
int Ask(int f, int s, int l = 0, int r = N, int id = 1) {
  if (f >= s || l >= r) return inf;
  get(l, r, id);
  if (s <= l || r <= f) return inf;
  if (f <= l && r <= s) return val[id];
  int mid = (l + r) >> 1;
  return min(Ask(f, s, l, mid, 2 * id), Ask(f, s, mid, r, 2 * id + 1));
}
void _Add(int pos, int x) {
  auto it = st.upper_bound({pos, 1e9});
  ++pos;
  if ((prev(it)->second) >= x) return;
  if (it == st.end() || (it->first) > pos)
    st.insert({pos, prev(it)->second}), it = next(it);
  while (it != st.begin() && (prev(it)->second) <= x) {
    int nm = prev(it)->second, ps = prev(it)->first;
    Add(ps, pos, x - nm);
    st.erase(prev(it));
    pos = ps;
  }
  st.insert({pos, x});
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  N = n + 1;
  for (int q = 0; q < 3; q++) {
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if (mp[q].count(x) == 0) mp[q][x] = i;
    }
  }
  for (int q = 0; q < 3; q++) {
    for (pair<int, int> p : mp[q]) {
      int num = 0;
      for (int w = 0; w < 3; w++) num += mp[w].count(p.first);
      if (num == 1) lim[q] = max(lim[q], p.second);
    }
  }
  build();
  st.insert({0, 0});
  _Add(n, lim[2]);
  for (pair<int, int> p : mp[1]) {
    if (mp[2].count(p.first) && mp[0].count(p.first) == 0)
      _Add(p.second - 1, mp[2][p.first]);
  }
  for (pair<int, int> p : mp[0]) {
    vec[p.second].push_back(p.first);
  }
  int ans = 3 * n;
  for (int i = n; i >= lim[0]; i--) {
    ans = min(ans, i + Ask(lim[1], N));
    for (int x : vec[i]) {
      bool b1 = mp[1].count(x), b2 = mp[2].count(x);
      if (b1 && b2) {
        _Add(mp[1][x] - 1, mp[2][x]);
      } else if (b1) {
        lim[1] = max(lim[1], mp[1][x]);
      } else if (b2) {
        _Add(n, mp[2][x]);
      }
    }
  }
  return cout << ans << endl, 0;
}
