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;
template <typename T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const int maxn = 100005;
const int inf = 1e9;
int n;
multiset<int> v;
set<pair<pair<int, int>, int> > s;
void add(int x, int val) { v.insert(n - min(n, x) + val); }
void remove(int x, int val) { v.erase(v.find(n - min(n, x) + val)); }
void addS(int l, int val) {
  auto it = s.upper_bound(make_pair(make_pair(l, inf), -1));
  if (it != s.begin()) {
    it--;
    if (it->second >= val)
      return;
    else {
      if (it->first.first == l) {
        remove(it->first.first, it->second);
        remove(it->first.second, it->second);
        s.erase(it);
        add(l, val);
      } else {
        remove(it->first.second, it->second);
        add(l - 1, it->second);
        auto t = make_pair(make_pair(it->first.first, l - 1), it->second);
        s.erase(it);
        s.insert(t);
        add(l, val);
      }
    }
  } else
    add(l, val);
  int r = l;
  while (true) {
    auto it = s.upper_bound(make_pair(make_pair(l, -1), -1));
    if (it == s.end()) {
      r = n + 1;
      break;
    }
    if (it->second >= val) {
      r = it->first.first - 1;
      break;
    }
    remove(it->first.first, it->second);
    remove(it->first.second, it->second);
    r = it->first.second;
    s.erase(it);
  }
  add(r, val);
  s.insert(make_pair(make_pair(l, r), val));
}
int a[3][maxn];
map<int, int> rev[3];
void print() {
  cerr << endl;
  for (auto x : s) {
    cerr << x.first.first << " " << x.first.second << " " << x.second << endl;
  }
  cerr << endl;
}
int main(int argc, char *argv[]) {
  scanf("%d", &n);
  set<int> e;
  for (int i = 0; i < 3; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%d", &a[i][j]);
      if (rev[i].find(a[i][j]) == rev[i].end()) rev[i][a[i][j]] = j;
      e.insert(a[i][j]);
    }
  v.insert(0);
  v.insert(n);
  s.insert(make_pair(make_pair(0, n + 1), 0));
  for (int x : e) {
    if (rev[0].find(x) != rev[0].end()) continue;
    if (rev[1].find(x) == rev[1].end()) {
      addS(0, rev[2][x]);
    } else {
      int y;
      if (rev[2].find(x) == rev[2].end())
        y = inf;
      else
        y = rev[2][x];
      addS(n + 1 - rev[1][x], y);
    }
  }
  int ans = n + (*v.begin());
  for (int i = n; i >= 1; i--) {
    if (rev[0][a[0][i]] < i) {
      ans = min(ans, i - 1 + (*v.begin()));
      continue;
    }
    int x = a[0][i];
    if (rev[1].find(x) == rev[1].end() && rev[2].find(x) == rev[2].end()) break;
    if (rev[1].find(x) == rev[1].end()) {
      addS(0, rev[2][x]);
    } else {
      int y;
      if (rev[2].find(x) == rev[2].end())
        y = inf;
      else
        y = rev[2][x];
      addS(n + 1 - rev[1][x], y);
    }
    ans = min(ans, i - 1 + (*v.begin()));
  }
  cout << ans << endl;
  return 0;
}
