Problem: 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.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
const int infi = 1e9 + 7;
const long long infl = 1e18 + 7;
long long get(const pair<long long, long long> &a) {
  return a.first + a.second;
}
struct diag_comp {
  bool operator()(const pair<long long, long long> &a,
                  const pair<long long, long long> &b) const {
    long long s = get(a) - get(b);
    return s < 0 || s == 0 && a.first < b.first ||
           s == 0 && a.first == b.first && a.second < b.second;
  }
};
struct compx {
  bool operator()(const pair<long long, long long> &a,
                  const pair<long long, long long> &b) const {
    return a.first < b.first || a.first == b.first && a.second > b.second;
  }
};
struct compy {
  bool operator()(const pair<long long, long long> &a,
                  const pair<long long, long long> &b) const {
    return a.second > b.second || a.second == b.second && a.first < b.first;
  }
};
set<pair<long long, long long>, diag_comp> cur_point;
set<pair<long long, long long>, compx> px;
set<pair<long long, long long>, compy> py;
long long get() { return get(*cur_point.begin()); }
void add_new_point(pair<long long, long long> a) {
  cur_point.insert(a);
  px.insert(a);
  py.insert(a);
  return;
}
void add_point(pair<long long, long long> a) {
  pair<long long, long long> p1 = *py.upper_bound(make_pair(-infl, a.second));
  pair<long long, long long> p2 =
      *(--px.upper_bound(make_pair(a.first, -infl)));
  if (p2.first < p1.first || p2.second > p1.second) return;
  vector<pair<long long, long long> > tmp;
  for (auto it = py.find(p1); *it != p2; ++it) tmp.push_back(*it);
  tmp.push_back(p2);
  for (int i = 0; i < ((int)tmp.size()); ++i) {
    py.erase(tmp[i]);
    px.erase(tmp[i]);
    cur_point.erase(tmp[i]);
  }
  pair<long long, long long> p = make_pair(p1.first, p2.second);
  add_new_point(make_pair(p.first, a.second));
  add_new_point(make_pair(a.first, p.second));
  return;
}
vector<int> all;
void norm(vector<int> &all) {
  vector<int> tmp;
  sort(all.begin(), all.end());
  if (all.size()) tmp.push_back(all[0]);
  for (int i = 1; i < (int)all.size(); ++i) {
    if (all[i] != all[i - 1]) tmp.push_back(all[i]);
  }
  all = tmp;
  return;
}
vector<vector<long long> > dp;
int ar[3][100500];
vector<pair<long long, long long> > sob;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < (3); ++i)
    for (int j = 0; j < (n); ++j) cin >> ar[i][j];
  for (int i = 0; i < (3); ++i)
    for (int j = 0; j < (n); ++j) all.push_back(ar[i][j]);
  norm(all);
  int m = all.size();
  dp.resize(m);
  for (int i = 0; i < (m); ++i) dp[i].resize(3, infl / 100);
  for (int i = 0; i < (3); ++i) {
    for (int j = 0; j < (n); ++j) {
      int a = ar[i][j];
      int k = lower_bound(all.begin(), all.end(), a) - all.begin();
      dp[k][i] = min(dp[k][i], (long long)j);
    }
  }
  for (int i = 0; i < (m); ++i) {
    sob.push_back(make_pair(dp[i][0], i));
  }
  sort(sob.begin(), sob.end());
  reverse(sob.begin(), sob.end());
  long long ans = n * 3;
  add_new_point(make_pair(0, 0));
  int j = 0;
  for (int i = n - 1; i >= -1; --i) {
    for (; j < (int)sob.size() && sob[j].first > i; ++j) {
      int k = sob[j].second;
      add_point(make_pair(dp[k][1] + 1, dp[k][2] + 1));
    }
    ans = min(ans, i + 1 + get());
  }
  cout << ans;
  return 0;
}