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>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
constexpr long long mod = 100000008;
const long long INF = mod * mod;
const long double eps = 1e-12;
const long double pi = acosl(-1.0);
long long mod_pow(long long x, long long n, long long m = mod) {
  if (n < 0) {
    long long res = mod_pow(x, -n, m);
    return mod_pow(res, m - 2, m);
  }
  if (abs(x) >= m) x %= m;
  if (x < 0) x += m;
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % m;
    x = x * x % m;
    n >>= 1;
  }
  return res;
}
struct modint {
  long long n;
  modint() : n(0) { ; }
  modint(long long m) : n(m) {
    if (n >= mod)
      n %= mod;
    else if (n < 0)
      n = (n % mod + mod) % mod;
  }
  operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) {
  a.n += b.n;
  if (a.n >= mod) a.n -= mod;
  return a;
}
modint operator-=(modint& a, modint b) {
  a.n -= b.n;
  if (a.n < 0) a.n += mod;
  return a;
}
modint operator*=(modint& a, modint b) {
  a.n = ((long long)a.n * b.n) % mod;
  return a;
}
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, long long n) {
  if (n == 0) return modint(1);
  modint res = (a * a) ^ (n / 2);
  if (n % 2) res = res * a;
  return res;
}
long long inv(long long a, long long p) {
  return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) {
  a = a / b;
  return a;
}
const int max_n = 100;
modint fact[max_n], factinv[max_n];
void init_f() {
  fact[0] = modint(1);
  for (int i = 0; i < max_n - 1; i++) {
    fact[i + 1] = fact[i] * modint(i + 1);
  }
  factinv[max_n - 1] = modint(1) / fact[max_n - 1];
  for (int i = max_n - 2; i >= 0; i--) {
    factinv[i] = factinv[i + 1] * modint(i + 1);
  }
}
modint comb(int a, int b) {
  if (a < 0 || b < 0 || a < b) return 0;
  return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
  if (a < 0 || b < 0 || a < b) return 0;
  return fact[a] * factinv[a - b];
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  vector<int> v;
  for (int val : a) v.push_back(val);
  for (int val : b) v.push_back(val);
  for (int val : c) v.push_back(val);
  sort((v).begin(), (v).end());
  v.erase(unique((v).begin(), (v).end()), v.end());
  vector<int> la(v.size(), mod);
  vector<int> lb(v.size(), mod);
  vector<int> lc(v.size(), mod);
  for (int i = 0; i < a.size(); i++) {
    int id = lower_bound((v).begin(), (v).end(), a[i]) - v.begin();
    la[id] = min(la[id], i + 1);
  }
  for (int i = 0; i < b.size(); i++) {
    int id = lower_bound((v).begin(), (v).end(), b[i]) - v.begin();
    lb[id] = min(lb[id], i + 1);
  }
  for (int i = 0; i < c.size(); i++) {
    int id = lower_bound((v).begin(), (v).end(), c[i]) - v.begin();
    lc[id] = min(lc[id], i + 1);
  }
  int ra = 0, rb = 0, rc = 0;
  for (int i = 0; i < v.size(); i++) {
    if (lb[i] == mod && lc[i] == mod) {
      ra = max(ra, la[i]);
    }
    if (la[i] == mod && lc[i] == mod) {
      rb = max(rb, lb[i]);
    }
    if (la[i] == mod && lb[i] == mod) {
      rc = max(rc, lc[i]);
    }
  }
  set<pair<int, int>> st;
  multiset<int> stval;
  st.insert({0, 2 * mod});
  st.insert({2 * mod, 0});
  stval.insert(0);
  auto add = [&](int x, int y) {
    pair<int, int> p = {x, -1};
    st.insert(p);
    auto itr = st.find(p);
    itr++;
    pair<int, int> nex = *itr;
    st.erase(p);
    if (nex.first == x) {
      if (nex.second >= y)
        return;
      else {
        st.insert({x, y});
        itr = st.find({x, y});
        st.erase(nex);
        itr--;
        int val = (*itr).first + nex.second;
        stval.erase(stval.find(val));
        while (true) {
          if ((*itr).second <= y) {
            pair<int, int> mem = *itr;
            itr--;
            st.erase(mem);
            int val = (*itr).first + mem.second;
            stval.erase(stval.find(val));
          } else
            break;
        }
        val = (*itr).first + y;
        stval.insert(val);
      }
    } else {
      if (nex.second >= y) return;
      itr--;
      int val = (*itr).first + nex.second;
      stval.erase(stval.find(val));
      st.insert({x, y});
      val = x + nex.second;
      stval.insert(val);
      while (true) {
        if ((*itr).second <= y) {
          pair<int, int> mem = *itr;
          itr--;
          st.erase(mem);
          int val = (*itr).first + mem.second;
          stval.erase(stval.find(val));
        } else
          break;
      }
      val = (*itr).first + y;
      stval.insert(val);
    }
  };
  vector<vector<pair<int, int>>> adbc(n - ra + 1);
  vector<vector<int>> adb(n - ra + 1);
  vector<vector<int>> adc(n - ra + 1);
  for (int i = 0; i < v.size(); i++) {
    if (la[i] <= ra || lb[i] <= rb || lc[i] <= rc) continue;
    if (lc[i] == mod) {
      adb[la[i] - ra].push_back(lb[i] - rb);
    } else if (lb[i] == mod) {
      adc[la[i] - ra].push_back(lc[i] - rc);
    } else if (la[i] == mod) {
      add(lb[i] - rb, lc[i] - rc);
    } else {
      adbc[la[i] - ra].push_back({lb[i] - rb, lc[i] - rc});
    }
  }
  int ans = 3 * n;
  for (int i = n - ra; i >= 0; i--) {
    int cost = ra + rb + rc + i + *stval.begin();
    ans = min(ans, cost);
    for (pair<int, int> p : adbc[i]) {
      add(p.first, p.second);
    }
    for (int valb : adb[i]) {
      add(valb, mod);
    }
    for (int valc : adc[i]) {
      add(mod, valc);
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
