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>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int a[300009], b[300009], c[300009], n, ct, lazy[300009 << 2], cnt[300009],
    CCC[300009];
int B[300009], BB[300009], C[300009], CC[300009], s[300009 << 2], vis[300009];
map<int, int> pm;
void shift(int nd, int x, int y) {
  int& ret = lazy[nd];
  int mid = (x + y) >> 1;
  if (~ret) {
    lazy[nd << 1] = lazy[nd << 1 | 1] = ret;
    s[nd << 1] = x + ret;
    s[nd << 1 | 1] = mid + 1 + ret;
    ret = -1;
  }
}
int tap(int p, int nd, int x, int y) {
  if (x == y) return max(0, lazy[nd]);
  shift(nd, x, y);
  int mid = (x + y) >> 1;
  if (p <= mid) return tap(p, nd << 1, x, mid);
  return tap(p, nd << 1 | 1, mid + 1, y);
}
void upd(int l, int r, int v, int nd, int x, int y) {
  if (l > y or x > r) return;
  if (l <= x and y <= r) {
    s[nd] = x + v;
    lazy[nd] = v;
    return;
  }
  shift(nd, x, y);
  int mid = (x + y) >> 1;
  upd(l, r, v, nd << 1, x, mid);
  upd(l, r, v, nd << 1 | 1, mid + 1, y);
  s[nd] = min(s[nd << 1], s[nd << 1 | 1]);
}
void remove(int x) {
  int posB = BB[x];
  int posC = CC[posB];
  if (!posB) posB = n + 1, posC = CCC[x];
  if (!posC) posC = 1000000007;
  int st = 0, en = posB - 1;
  while (st + 1 < en) {
    int mid = (st + en) >> 1;
    if (tap(mid, 1, 0, n) <= posC)
      en = mid;
    else
      st = mid;
  }
  if (tap(st, 1, 0, n) <= posC)
    upd(st, posB - 1, posC, 1, 0, n);
  else if (tap(en, 1, 0, n) <= posC)
    upd(en, posB - 1, posC, 1, 0, n);
}
void build(int nd, int x, int y) {
  lazy[nd] = -1;
  if (x == y) {
    s[nd] = x;
    return;
  }
  int mid = (x + y) >> 1;
  build(nd << 1, x, mid);
  build(nd << 1 | 1, mid + 1, y);
  s[nd] = min(s[nd << 1], s[nd << 1 | 1]);
}
int main() {
  scanf("%d", &n);
  build(1, 0, n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i), pm[a[i]] = true;
  for (int i = 1; i <= n; i++) scanf("%d", b + i), pm[b[i]] = true;
  for (int i = 1; i <= n; i++) scanf("%d", c + i), pm[c[i]] = true;
  for (__typeof((pm).begin()) it = (pm).begin(); it != (pm).end(); it++)
    it->second = ++ct;
  for (int i = 1; i <= n; i++) a[i] = pm[a[i]], vis[a[i]] = true;
  for (int i = 1; i <= n; i++) b[i] = pm[b[i]], vis[b[i]] = true;
  for (int i = 1; i <= n; i++) c[i] = pm[c[i]], vis[c[i]] = true;
  for (int i = 1; i <= n; i++) {
    if (!B[b[i]]) BB[b[i]] = i;
    B[b[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (!C[c[i]]) {
      CC[BB[c[i]]] = i;
      CCC[c[i]] = i;
    }
    C[c[i]] = true;
  }
  for (int i = 1; i <= n; i++) cnt[a[i]]++;
  for (int i = 1; i <= ct; i++)
    if (!cnt[i] and vis[i]) remove(i);
  int ans = 1000000007, pos = n + 1;
  for (int i = n; i >= 1; i--) {
    umin(ans, i + s[1]);
    cnt[a[i]]--;
    if (!cnt[a[i]]) {
      if (!C[a[i]] and !B[a[i]]) break;
      remove(a[i]);
    }
    pos = i;
  }
  printf("%d\n", min(ans, s[1] + 1000000007 * (pos != 1)));
  return 0;
}
