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;
const int MAXN = 1 << 17;
const int MAXV = 3 * MAXN;
int N;
struct segtree {
  map<int, int> ai;
  int tree[2 * MAXN];
  int lazy[2 * MAXN];
  segtree() { memset(lazy, -1, sizeof(lazy)); }
  void put(int cur, int v) {
    tree[cur] = v;
    lazy[cur] = v;
  }
  void down(int cur) {
    if (lazy[cur] != -1) {
      put(2 * cur, lazy[cur]);
      put(2 * cur + 1, lazy[cur]);
      lazy[cur] = -1;
    }
  }
  void update(int a, int b, int v, int cur = 1, int lt = 0, int rt = MAXN) {
    if (rt <= a || b <= lt) {
      return;
    }
    if (cur == 1) {
      int rtv = prev(ai.upper_bound(b))->second;
      ai[a] = v;
      ai[b] = rtv;
      ai.erase(next(ai.find(a)), ai.find(b));
    }
    if (a <= lt && rt <= b) {
      put(cur, v);
      return;
    }
    down(cur);
    int mid = (lt + rt) / 2;
    update(a, b, v, 2 * cur, lt, mid);
    update(a, b, v, 2 * cur + 1, mid, rt);
    tree[cur] = min(tree[2 * cur], tree[2 * cur + 1] + (mid - lt));
  }
  int query(int a, int b, int cur = 1, int lt = 0, int rt = MAXN) {
    if (rt <= a || b <= lt) {
      return 3 * N;
    }
    if (a <= lt && rt <= b) {
      return tree[cur];
    }
    down(cur);
    int mid = (lt + rt) / 2;
    return min(query(a, b, 2 * cur, lt, mid),
               query(a, b, 2 * cur + 1, mid, rt) + (mid - lt));
  }
  int at(int x) { return ai.lower_bound(x)->second; }
};
int A[MAXN], B[MAXN], C[MAXN];
vector<int> aind[MAXV], donaldjtrump[MAXV], cind[MAXV];
vector<int> vals;
segtree seg;
void read(int *arr) {
  for (int i = 0; i < N; i++) {
    scanf("%d", &arr[i]);
  }
  vals.insert(vals.end(), arr, arr + N);
}
void compr(int *arr, vector<int> *inds) {
  for (int i = 0; i < N; i++) {
    arr[i] = lower_bound((vals).begin(), (vals).end(), arr[i]) - vals.begin();
    inds[arr[i]].push_back(i);
  }
}
int occ[MAXV], nzero;
void addocc(int x, int c) {
  nzero -= (occ[x] == 0);
  occ[x] += c;
  nzero += (occ[x] == 0);
}
int main() {
  scanf("%d", &N);
  read(A);
  read(B);
  read(C);
  sort((vals).begin(), (vals).end());
  vals.resize(unique((vals).begin(), (vals).end()) - vals.begin());
  compr(A, aind);
  compr(B, donaldjtrump);
  compr(C, cind);
  nzero = vals.size();
  for (int i = 0; i < N; i++) {
    addocc(A[i], 1);
    addocc(C[i], 1);
  }
  seg.ai[0] = seg.ai[MAXN];
  fill_n(seg.tree, 2 * MAXN, 3 * N);
  int ans = 3 * N;
  for (int i = 0, j = N; i <= N; i++) {
    while (j > 0 && !nzero && occ[C[j - 1]] > 1) {
      j--;
      addocc(C[j], -1);
    }
    int val = (nzero ? 3 * N : j);
    seg.update(i, i + 1, val);
    ans = min(ans, N + i + val);
    addocc(B[i], 1);
  }
  for (int i = N - 1; i >= 0; i--) {
    if (i == aind[A[i]][0]) {
      int ind = (donaldjtrump[A[i]].empty() ? N + 1 : donaldjtrump[A[i]][0]);
      int ic = (cind[A[i]].empty() ? 3 * N : cind[A[i]][0]);
      int lo = -1, hi = ind + 1;
      while (hi - lo > 1) {
        int mid = lo + (hi - lo) / 2;
        if (seg.at(mid) <= ic) {
          hi = mid;
        } else {
          lo = mid;
        }
      }
      if (hi <= ind) {
        seg.update(hi, ind + 1, ic + 1);
      }
    }
    ans = min(ans, i + seg.query(0, N + 1));
  }
  printf("%d\n", ans);
}
