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;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 3e5 + 7;
const int inf = 1e9 + 7;
int a[3][N];
int ind[N][3];
multiset<pair<int, int> > q;
multiset<int> val;
void add(int i) {
  pair<int, int> x = {ind[i][1] - 1, ind[i][2]};
  auto it = q.lower_bound(x);
  if (it != q.end() && it->second >= x.second) {
    return;
  }
  while (!q.empty()) {
    auto it = q.upper_bound(x);
    if (it == q.begin()) break;
    it--;
    if (it->second <= x.second) {
      int my_first = 0;
      if (it != q.begin()) {
        my_first = prev(it)->first + 1;
      }
      if (next(it) != q.end()) {
        int _x = next(it)->first, _y = next(it)->second;
        val.erase(val.find(it->first + 1 + _y));
        val.insert(my_first + _y);
      }
      val.erase(val.find(my_first + it->second));
      q.erase(it);
    } else {
      break;
    }
  }
  int my_first = 0;
  q.insert(x);
  it = q.find(x);
  if (it != q.begin()) {
    my_first = prev(it)->first + 1;
  }
  if (next(it) != q.end()) {
    int _x = next(it)->first, _y = next(it)->second;
    val.erase(val.find(my_first + _y));
    val.insert(x.first + 1 + _y);
  }
  val.insert(my_first + x.second);
}
int get() {
  if (q.empty()) {
    return 0;
  } else {
    int ret = q.rbegin()->first + 1;
    ret = min(ret, *val.begin());
    return ret;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p;
  for (int t = 0; t < 3; t++) {
    for (int i = 0; i < n; i++) {
      cin >> a[t][i];
      p.push_back(a[t][i]);
    }
  }
  sort(p.begin(), p.end());
  p.resize(unique(p.begin(), p.end()) - p.begin());
  int m = (int)p.size();
  int sz = 0;
  for (int i = 0; i < m; i++) {
    for (int t = 0; t < 3; t++) {
      ind[i][t] = inf + sz;
      sz++;
    }
  }
  for (int t = 0; t < 3; t++) {
    for (int i = 0; i < n; i++) {
      a[t][i] = lower_bound(p.begin(), p.end(), a[t][i]) - p.begin();
      ind[a[t][i]][t] = min(ind[a[t][i]][t], i + 1);
    }
  }
  for (int i = 0; i < m; i++) {
    if (ind[i][0] >= inf) {
      add(i);
    }
  }
  int ans = n + get();
  for (int i = n - 1; i >= 0; i--) {
    int val = a[0][i];
    if (ind[val][0] == i + 1) {
      add(val);
    }
    ans = min(ans, i + get());
  }
  cout << ans << '\n';
}
