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 N = 300005;
int n, m, a[N], X[N], Y[N], ans, first[N], now[N];
bool bz[N];
map<int, int> h;
set<pair<int, int> > t;
multiset<int> T;
pair<int, int> tmp;
bool operator<(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
char c;
int read() {
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    ;
  int x = c - 48;
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x;
}
void ins(int x) {
  tmp.first = X[x];
  tmp.second = Y[x];
  set<pair<int, int> >::iterator i = t.lower_bound(tmp);
  if (i->second >= Y[x]) return;
  for (i = t.lower_bound(tmp), i--; i->second <= Y[x];
       t.erase(i), i = t.lower_bound(tmp), i--)
    T.erase(T.find(now[i->first]));
  t.insert(tmp);
  T.erase(T.find(now[i->first]));
  T.insert(now[i->first] = i->first + Y[x]);
  T.insert(now[X[x]] = X[x] + t.upper_bound(tmp)->second);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    if (h.find(x) == h.end()) {
      h.insert(make_pair(x, a[i] = ++m));
      X[m] = Y[m] = n * 3;
    } else
      a[i] = h.find(x)->second;
  }
  for (int i = 1; i <= n; i++) {
    int x = read(), id;
    if (h.find(x) == h.end()) {
      h.insert(make_pair(x, id = ++m));
      X[m] = Y[m] = n * 3;
    } else
      id = h.find(x)->second;
    if (X[id] > i) X[id] = i;
  }
  for (int i = 1; i <= n; i++) {
    int x = read(), id;
    if (h.find(x) == h.end()) {
      h.insert(make_pair(x, id = ++m));
      X[m] = Y[m] = n * 3;
    } else
      id = h.find(x)->second;
    if (Y[id] > i) Y[id] = i;
  }
  for (int i = n; i; i--) {
    bz[a[i]] = 1;
    first[a[i]] = i;
  }
  tmp.first = 0;
  tmp.second = n * 3 + 1;
  t.insert(tmp);
  T.insert(now[0] = n << 1);
  tmp.first = n * 3 + 1;
  tmp.second = 0;
  t.insert(tmp);
  for (int i = 1; i <= m; i++)
    if (!bz[i]) ins(i);
  ans = n + *(T.begin());
  for (int i = n; i; i--) {
    if (first[a[i]] == i) ins(a[i]);
    ans = min(ans, i - 1 + *(T.begin()));
  }
  printf("%d\n", ans);
  return 0;
}
