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 long long N = 1000005;
int n;
long long a[N], b[N], c[N];
map<long long, long long> last1, last2, last3;
long long mx1[N], mx2[N], same_mx[N];
long long mmx1, mmx2, mmx3;
vector<pair<long long, pair<long long, long long> > > v;
set<long long> was;
set<long long>::iterator it;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    was.insert(a[i]);
    if (!last1.count(a[i])) last1[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    was.insert(b[i]);
    if (!last2.count(b[i])) last2[b[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    was.insert(c[i]);
    if (!last3.count(c[i])) last3[c[i]] = i;
  }
  for (it = was.begin(); it != was.end(); it++) {
    pair<long long, pair<long long, long long> > cur;
    if (!last1.count(*it))
      cur.first = N;
    else
      cur.first = last1[*it];
    if (!last2.count(*it))
      cur.second.first = N;
    else
      cur.second.first = last2[*it];
    if (!last3.count(*it))
      cur.second.second = N;
    else
      cur.second.second = last3[*it];
    v.push_back(cur);
  }
  sort(v.begin(), v.end());
  long long ans = N;
  for (int i = 0; i < v.size(); i++) {
    mmx1 = max(mmx1, v[i].first);
    mmx2 = max(mmx2, v[i].second.first);
    mmx3 = max(mmx3, v[i].second.second);
  }
  ans = min(ans, mmx1);
  ans = min(ans, mmx2);
  ans = min(ans, mmx3);
  if (1) {
    vector<pair<long long, long long> > vv;
    for (int i = 0; i < v.size(); i++)
      vv.push_back(make_pair(v[i].first, v[i].second.first));
    sort(vv.begin(), vv.end());
    long long mx = 0;
    for (int i = vv.size() - 1; i >= 0; i--) {
      ans = min(ans, vv[i].first + mx);
      mx = max(mx, vv[i].second);
    }
    ans = min(ans, mx);
  }
  if (1) {
    vector<pair<long long, long long> > vv;
    for (int i = 0; i < v.size(); i++)
      vv.push_back(make_pair(v[i].second.first, v[i].second.second));
    sort(vv.begin(), vv.end());
    long long mx = 0;
    for (int i = vv.size() - 1; i >= 0; i--) {
      ans = min(ans, vv[i].first + mx);
      mx = max(mx, vv[i].second);
    }
    ans = min(ans, mx);
  }
  if (1) {
    vector<pair<long long, long long> > vv;
    for (int i = 0; i < v.size(); i++)
      vv.push_back(make_pair(v[i].second.first, v[i].first));
    sort(vv.begin(), vv.end());
    long long mx = 0;
    for (int i = vv.size() - 1; i >= 0; i--) {
      ans = min(ans, vv[i].first + mx);
      mx = max(mx, vv[i].second);
    }
    ans = min(ans, mx);
  }
  for (int i = v.size() - 1; i >= 0; i--) {
    pair<long long, long long> cur = v[i].second;
    if (cur.first == cur.second) {
      mx2[i] = mx2[i + 1];
      mx1[i] = mx1[i + 1];
      same_mx[i] = max(same_mx[i + 1], cur.first);
    } else if (cur.first > cur.second) {
      mx2[i] = max(mx2[i + 1], cur.second);
      mx1[i] = mx1[i + 1];
      same_mx[i] = same_mx[i + 1];
    } else if (cur.first < cur.second) {
      mx1[i] = max(mx1[i + 1], cur.first);
      mx2[i] = mx2[i + 1];
      same_mx[i] = same_mx[i + 1];
    }
  }
  long long mm1 = mx1[0], mm2 = mx2[0], mm3 = same_mx[0];
  if (mm3 < max(mm1, mm2))
    ans = min(ans, mm1 + mm2);
  else
    ans = min(ans, mm3 + min(mm1, mm2));
  for (int i = 0; i < v.size(); i++) {
    int cur = v[i].first;
    long long m1 = mx1[i + 1], m2 = mx2[i + 1], m3 = same_mx[i + 1];
    if (m3 < max(m1, m2))
      ans = min(ans, cur + m1 + m2);
    else
      ans = min(ans, cur + m3 + min(m1, m2));
  }
  if (ans == N) cout << "syka ia sam huey ot napisanogo";
  cout << ans << endl;
}
