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;
struct point {
  int x, y;
} p[300010];
int n, a[100010], b[100010], c[100010], vis[300010], d[300010], Min, Y[400010],
    inf = 100000000;
set<int> A;
multiset<int> B;
void read(int &x) {
  char ch = getchar();
  int mark = 1;
  for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar())
    ;
  if (ch == '-') mark = -1, ch = getchar();
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
  x *= mark;
}
int Get(int x, int y) {
  if (x > n || y > n) return inf;
  return x + y;
}
void Add(point X) {
  set<int>::iterator R, L, tmp;
  R = A.upper_bound(X.x);
  if (Y[*R] < X.y) {
    L = R;
    for (; Y[*L] < X.y; --L)
      ;
    for (set<int>::iterator it = L; it != R; ++it) {
      set<int>::iterator nxt = it;
      ++nxt;
      B.erase(B.find(Get((*it), Y[*nxt])));
    }
    B.insert(Get((*L), X.y));
    B.insert(Get(X.x, Y[*R]));
    if (L != R) {
      set<int>::iterator it = L;
      ++it;
      for (; it != R;) {
        tmp = it;
        ++it;
        A.erase(tmp);
      }
    }
    A.insert(X.x);
    Y[X.x] = X.y;
  }
}
int main() {
  read(n);
  int cnt = 0;
  for (int i = 1; i <= n; i++) read(a[i]), d[++cnt] = a[i];
  for (int i = 1; i <= n; i++) read(b[i]), d[++cnt] = b[i];
  for (int i = 1; i <= n; i++) read(c[i]), d[++cnt] = c[i];
  sort(d + 1, d + cnt + 1);
  cnt = unique(d + 1, d + cnt + 1) - (d + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(d + 1, d + cnt + 1, a[i]) - d;
    b[i] = lower_bound(d + 1, d + cnt + 1, b[i]) - d;
    c[i] = lower_bound(d + 1, d + cnt + 1, c[i]) - d;
  }
  for (int i = 1; i <= n; i++) vis[a[i]]++;
  for (int i = 1; i <= cnt; i++) p[i].x = p[i].y = n + i;
  for (int i = n; i; i--) {
    p[b[i]].x = i;
    p[c[i]].y = i;
  }
  Min = 3 * n;
  point tmp;
  tmp.x = 0, Y[tmp.x] = n + cnt + 1;
  A.insert(0);
  tmp.x = n + cnt + 1;
  Y[tmp.x] = 0;
  A.insert(n + cnt + 1);
  B.insert(Get(0, 0));
  for (int i = 1; i <= cnt; i++)
    if (!vis[i]) Add(p[i]);
  Min = min(Min, (*B.begin()) + n);
  for (int i = n; i; i--) {
    vis[a[i]]--;
    if (!vis[a[i]]) {
      if (p[a[i]].x > n && p[a[i]].y > n) break;
      Add(p[a[i]]);
    }
    Min = min(Min, (*B.begin()) + i - 1);
  }
  printf("%d\n", Min);
  return 0;
}
