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;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MAX = 100100;
int A[3][MAX];
map<int, int> B[3];
set<pair<int, int> > S;
multiset<int> VS;
int VAL;
void print() {
  for (__typeof(S.begin()) it = S.begin(); it != S.end(); it++) {
    cout << "(" << it->first << ", " << it->second << ") ";
  }
  cout << endl;
}
void rem(int val) {
  VS.erase(VS.find(val));
  if (VS.empty())
    VAL = INF;
  else
    VAL = *VS.begin();
}
void ad(int val) {
  VS.insert(val);
  VAL = *VS.begin();
}
void remove(set<pair<int, int> >::iterator);
int getVal(set<pair<int, int> >::iterator it) {
  int y = it->second;
  it--;
  int x = it->first;
  if (y == -1) y++;
  if (x == -1) x++;
  int val = x + y;
  return val;
}
void add(pair<int, int> a) {
  int x = a.first;
  int y = a.second;
  while (true) {
    set<pair<int, int> >::iterator it = S.upper_bound(a);
    if (it->second >= y) return;
    it--;
    if (it->second <= y) {
      remove(it);
      continue;
    }
    break;
  }
  set<pair<int, int> >::iterator it = S.upper_bound(a);
  int val = getVal(it);
  rem(val);
  S.insert(a);
  it = S.upper_bound(a);
  val = getVal(it);
  ad(val);
  it--;
  val = getVal(it);
  ad(val);
}
void remove(set<pair<int, int> >::iterator it) {
  pair<int, int> a = *it;
  int val = getVal(it);
  rem(val);
  it++;
  val = getVal(it);
  rem(val);
  it--;
  S.erase(it);
  it = S.upper_bound(a);
  val = getVal(it);
  ad(val);
}
pair<int, int> getXY(int v) {
  int x = INF, y = INF;
  if (B[1].count(v)) x = B[1][v];
  if (B[2].count(v)) y = B[2][v];
  x++;
  y++;
  return make_pair(x, y);
}
int main() {
  S.insert(make_pair(-1, INF * 2));
  S.insert(make_pair(INF * 2, -1));
  VS.insert(0);
  VAL = 0;
  int n;
  scanf("%d", &n);
  for (int it = (0); it < (3); it++) {
    for (int i = (0); i < (n); i++) {
      scanf("%d", &A[it][i]);
    }
  }
  vector<int> all;
  for (int it = (0); it < (3); it++) {
    for (int i = (n)-1; i >= (0); i--) {
      B[it][A[it][i]] = i;
      all.push_back(A[it][i]);
    }
  }
  sort(all.begin(), all.end());
  all.erase(unique(all.begin(), all.end()), all.end());
  for (int i = (0); i < ((int)all.size()); i++) {
    int v = all[i];
    if (B[0].count(v)) continue;
    pair<int, int> xy = getXY(v);
    add(xy);
  }
  int res = n + VAL;
  for (int i = (n)-1; i >= (0); i--) {
    int v = A[0][i];
    if (B[0][v] != i) {
      res = min(res, VAL + i);
      continue;
    }
    pair<int, int> xy = getXY(v);
    if (xy == make_pair(0, 0)) break;
    add(xy);
    int cur = i + VAL;
    res = min(res, cur);
  }
  cout << res << endl;
}
