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.
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool getmin(T *a, const T &b) {
  if (b < *a) {
    *a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool getmax(T *a, const T &b) {
  if (b > *a) {
    *a = b;
    return true;
  }
  return false;
}
template <class T>
inline void read(T *a) {
  char c;
  while (isspace(c = getchar())) {
  }
  bool flag = 0;
  if (c == '-')
    flag = 1, *a = 0;
  else
    *a = c - 48;
  while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
  if (flag) *a = -*a;
}
const int mo = 1000000007;
template <class T>
T pow(T a, T b, int c = mo) {
  T res = 1;
  for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c)
    if (b & i) res = 1LL * res * a % c;
  return res;
}
const int N = 310000;
struct node {
  int x, y, z;
} T[N];
bool operator<(node A, node B) { return A.x < B.x; }
int tag[N * 4], mx[N * 4], val[N * 4];
pair<int, int> a[N], b[N], c[N];
int n, m;
void down(int u, int L, int R) {
  int mid = (L + R) >> 1;
  if (tag[u]) {
    tag[u * 2] = tag[u];
    mx[u * 2] = L + tag[u], val[u * 2] = tag[u];
    tag[u * 2 + 1] = tag[u];
    mx[u * 2 + 1] = mid + 1 + tag[u], val[u * 2 + 1] = tag[u];
    tag[u] = 0;
  }
}
void update(int u) {
  assert(val[u * 2] >= val[u * 2 + 1]);
  mx[u] = min(mx[u * 2], mx[u * 2 + 1]);
  val[u] = min(val[u * 2], val[u * 2 + 1]);
}
void build(int u, int L, int R) {
  if (L == R) {
    mx[u] = L;
    return;
  }
  int mid = (L + R) >> 1;
  build(u * 2, L, mid);
  build(u * 2 + 1, mid + 1, R);
  update(u);
}
void modify(int u, int L, int R, int l, int r, int d) {
  if (l > r) return;
  if (l <= L && r >= R) {
    assert(val[u] < d);
    tag[u] = d;
    mx[u] = L + d;
    val[u] = d;
    return;
  }
  down(u, L, R);
  int mid = (L + R) >> 1;
  if (r <= mid)
    modify(u * 2, L, mid, l, r, d);
  else if (l > mid)
    modify(u * 2 + 1, mid + 1, R, l, r, d);
  else {
    modify(u * 2, L, mid, l, mid, d);
    modify(u * 2 + 1, mid + 1, R, mid + 1, r, d);
  }
  update(u);
}
int find(int u, int L, int R, int d) {
  if (val[u] >= d) return n + 1;
  if (L == R) return L;
  down(u, L, R);
  int mid = (L + R) >> 1;
  assert(val[u * 2] >= val[u * 2 + 1]);
  if (val[u * 2] < d)
    return find(u * 2, L, mid, d);
  else
    return find(u * 2 + 1, mid + 1, R, d);
}
int pool[N];
int main() {
  cin >> n;
  for (int i = (1); i <= (n); ++i)
    read(&a[i].first), a[i].second = i, pool[++m] = a[i].first;
  for (int i = (1); i <= (n); ++i)
    read(&b[i].first), b[i].second = i, pool[++m] = b[i].first;
  for (int i = (1); i <= (n); ++i)
    read(&c[i].first), c[i].second = i, pool[++m] = c[i].first;
  sort(pool + 1, pool + m + 1);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  sort(c + 1, c + n + 1);
  m = unique(pool + 1, pool + m + 1) - pool - 1;
  for (int i = (1); i <= (m); ++i) {
    T[i].x = lower_bound(a + 1, a + n + 1, std::make_pair(pool[i], 0)) - a;
    if (a[T[i].x].first == pool[i])
      T[i].x = a[T[i].x].second;
    else
      T[i].x = 3 * n + 1;
    T[i].y = lower_bound(b + 1, b + n + 1, std::make_pair(pool[i], 0)) - b;
    if (b[T[i].y].first == pool[i])
      T[i].y = b[T[i].y].second;
    else
      T[i].y = n + 1;
    T[i].z = lower_bound(c + 1, c + n + 1, std::make_pair(pool[i], 0)) - c;
    if (c[T[i].z].first == pool[i])
      T[i].z = c[T[i].z].second;
    else
      T[i].z = 3 * n + 1;
  }
  build(1, 0, n);
  sort(T + 1, T + m + 1);
  int ans = T[m].x;
  for (int i = (m); i >= (1); --i) {
    int l = find(1, 0, n, T[i].z);
    int r = T[i].y - 1;
    modify(1, 0, n, l, r, T[i].z);
    if (T[i].x != T[i - 1].x && T[i - 1].x <= n) {
      getmin(&ans, T[i - 1].x + mx[1]);
    }
  }
  cout << ans << endl;
  return 0;
}
