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>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int nmax = 511222;
void read(int a[nmax], int n, int all[]) {
  for (int(i) = 0; (i) < (n); ++(i)) {
    scanf("%d", &a[i]);
    all[i] = a[i];
  }
}
void make_small(int a[nmax], int n, int all[nmax], int sz) {
  for (int(i) = 0; (i) < (n); ++(i)) {
    a[i] = lower_bound(all, all + sz, a[i]) - all;
  }
}
int a[nmax], b[nmax], c[nmax], all[nmax];
int n, sz;
int d[nmax];
int cntd;
void add(int val) {
  if (d[val] == 0) ++cntd;
  d[val]++;
}
void del(int val) {
  d[val]--;
  if (d[val] == 0) --cntd;
}
int itinc[nmax];
int pos[nmax];
int prv[nmax];
int get_col(int v) {
  if (prv[v] == v) return v;
  return prv[v] = get_col(prv[v]);
}
int TT[nmax];
void update(int x, int val) {
  ++x;
  for (int i = x; i < nmax; i = 2 * i - (i & (i - 1))) TT[i] += val;
}
int get(int x) {
  ++x;
  int ans = 0;
  for (int i = x; i > 0; i = (i & (i - 1))) ans += TT[i];
  return ans;
}
int posb[nmax];
int main() {
  scanf("%d", &n);
  read(a, n, all);
  read(b, n, all + n);
  read(c, n, all + n + n);
  sort(all, all + 3 * n);
  int sall = 1;
  for (int(i) = (1); (i) <= (3 * n - 1); ++(i)) {
    if (all[i] != all[i - 1]) all[sall++] = all[i];
  }
  make_small(a, n, all, sall);
  make_small(b, n, all, sall);
  make_small(c, n, all, sall);
  sz = sall;
  for (int(i) = 0; (i) < (n); ++(i)) add(c[i]);
  for (int i = n; i < n + sz; ++i) {
    c[i] = i - n;
    add(c[i]);
  }
  int mn = 1000000000;
  int itC = n + sz;
  for (int i = 0; i <= n; ++i) {
    while (itC > 0) {
      del(c[itC - 1]);
      if (cntd < sz) {
        add(c[itC - 1]);
        break;
      } else
        --itC;
    }
    itinc[i] = itC;
    update(i, itC);
    update(i + 1, -itC);
    if (i == 0 || itinc[i] != itinc[i - 1]) {
      if (itC <= n) {
        mn = min(mn, i + itC);
      }
    }
    if (i != n) add(b[i]);
  }
  memset((posb), -1, sizeof(posb));
  for (int(i) = (n); (i)--;) posb[b[i]] = i;
  memset((pos), -1, sizeof(pos));
  for (int(i) = (n + sz); (i)--;) pos[c[i]] = i;
  for (int(i) = (1); (i) <= (n + sz); ++(i)) {
    if (i - 1 == pos[c[i - 1]])
      prv[i] = i;
    else
      prv[i] = i - 1;
  }
  int ANS = mn;
  for (int(I) = 0; (I) < (n); ++(I)) {
    ANS = min(ANS, I + 1 + mn);
    int cur = a[I];
    for (int(stessssp) = 0; (stessssp) < (1); ++(stessssp)) {
      int i = pos[cur];
      if (i == -1) break;
      prv[i + 1] = i;
      int l = -1, r = n + 1;
      while (l < r - 1) {
        int mid = (l + r) / 2;
        if (get(mid) > i + 1)
          l = mid;
        else
          r = mid;
      }
      int L = l + 1;
      l = -1, r = n + 1;
      while (l < r - 1) {
        int mid = (l + r) / 2;
        if (get(mid) >= i + 1)
          l = mid;
        else
          r = mid;
      }
      int R = l;
      if (get(L) == i + 1) {
        for (int K = L; K <= R; ++K) {
          int ni = i + 1;
          while (1) {
            ni = get_col(ni);
            if (ni == 0 || posb[c[ni - 1]] == -1 || posb[c[ni - 1]] >= K) break;
            while (ni - 1 >= 0 && posb[c[ni - 1]] < K) --ni;
          }
          update(K, -(i + 1 - ni));
          update(K + 1, (i + 1 - ni));
          if (ni <= n) {
            mn = min(mn, K + ni + 1);
            ANS = min(ANS, I + mn);
          }
        }
      }
    }
    pos[cur] = -1;
  }
  cout << ANS << endl;
  return 0;
}
