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;
struct foo {
  int y, z, s;
  foo() {}
  foo(int _y, int _z) : y(_y), z(_z), s(_y + _z) {}
  bool operator<(const foo& rhs) const {
    if (s != rhs.s) return s < rhs.s;
    return y < rhs.y;
  }
};
const int N = 100005;
int n, a[3][N], x[N][3];
bool vst[N];
map<int, int> idx, mp, mpn;
set<foo> st;
void insert(int k) {
  int y0, z0, y1 = x[k][1], z1 = x[k][2];
  map<int, int>::iterator i = mp.lower_bound(y1);
  if (i->second >= z1) return;
  if (i->first == y1)
    i->second = z1;
  else
    i = mp.insert(make_pair(y1, z1)).first;
  while (i != mp.begin()) {
    map<int, int>::iterator j = i;
    --j;
    y0 = j->first;
    z0 = j->second;
    st.erase(foo(y0, mpn[y0]));
    if (z1 < z0) break;
    mp.erase(j);
  }
  if (i != mp.begin()) {
    st.insert(foo(y0, mpn[y0] = z1));
  }
  if (++i != mp.end()) {
    st.insert(foo(y1, mpn[y1] = i->second));
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 3; ++i) {
    for (int j = 1; j <= n; ++j) {
      scanf("%d", &a[i][j]);
      idx[a[i][j]] = 0;
    }
  }
  map<int, int>::iterator it = idx.begin();
  for (int i = 0; it != idx.end(); ++it, ++i) {
    it->second = i;
  }
  for (int i = n; i; --i) {
    for (int j = 0; j < 3; ++j) {
      a[j][i] = idx[a[j][i]];
      x[a[j][i]][j] = i;
    }
  }
  mp[0] = n + 1;
  mp[n + 1] = 0;
  mpn[0] = 0;
  st.insert(foo(0, 0));
  for (size_t i = 0; i < idx.size(); ++i) {
    for (int j = 0; j < 3; ++j) {
      if (!x[i][j]) x[i][j] = n + 1;
    }
    if (x[i][0] == n + 1) insert(i);
  }
  int ans = n + st.begin()->s;
  for (int i = n; i; --i) {
    int k = a[0][i];
    if (i == x[k][0]) {
      if (x[k][1] == n + 1 && x[k][2] == n + 1) {
        break;
      }
      insert(k);
    }
    ans = min(ans, i - 1 + st.begin()->s);
  }
  printf("%d\n", ans);
}
