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 N = 1e5 + 10, INF = 1e9;
map<int, int> mp;
int a[N], b[N], c[N];
int f1[3 * N], f2[3 * N], f3[3 * N];
set<pair<int, int> > st, foo;
set<int> res;
vector<pair<int, int> > tmp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    mp[b[i]] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    mp[c[i]] = 0;
  }
  int cnt = 0;
  for (auto X : mp) {
    mp[X.first] = cnt++;
  }
  for (int i = 0; i < n; i++) {
    a[i] = mp[a[i]];
    b[i] = mp[b[i]];
    c[i] = mp[c[i]];
  }
  for (auto X : mp) {
    int key = mp[X.first];
    f1[key] = f2[key] = f3[key] = INF;
  }
  for (int i = n - 1; i >= 0; i--) {
    f1[a[i]] = i;
    f2[b[i]] = i;
    f3[c[i]] = i;
  }
  for (auto X : mp) {
    foo.insert({f3[mp[X.first]], mp[X.first]});
  }
  for (int i = 0; i < n; i++) foo.erase({f3[a[i]], a[i]});
  int ans = INF;
  for (int i = 0; i <= n; i++) {
    if (i) foo.erase({f3[b[i - 1]], b[i - 1]});
    if ((int)foo.size()) {
      int mn = (*foo.rbegin()).first;
      mn++;
      st.insert({i, mn});
      res.insert(i + mn);
    } else {
      st.insert({i, 0});
      res.insert(i);
    }
    ans = min(ans, n + *(res.begin()));
  }
  for (int i = n - 1; i >= 0; i--) {
    if (f1[a[i]] < i) {
      ans = min(ans, i + *(res.begin()));
    } else {
      int pos = f2[a[i]], td = f3[a[i]];
      auto it = st.upper_bound(pair<int, int>(pos, INF));
      if (it != st.begin()) --it;
      tmp.clear();
      while ((*it).second <= td) {
        tmp.push_back(*it);
        if (it == st.begin()) break;
        --it;
      }
      if ((int)tmp.size()) {
        for (auto X : tmp) st.erase(X), res.erase(X.first + X.second);
        auto X = tmp.back();
        st.insert({X.first, td + 1});
        res.insert(X.first + td + 1);
      }
      ans = min(ans, i + *(res.begin()));
    }
  }
  cout << ans << endl;
}
