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 INF = -1;
int infAdd(int x, int y) { return (x == INF || (y == INF)) ? INF : (x + y); }
int infAdd(const vector<int>& arr) {
  int out = 0;
  for (int x : arr) out = infAdd(out, x);
  return out;
}
int infMin(int x, int y) {
  if (x == INF) return y;
  if (y == INF) return x;
  return min(x, y);
}
int infMax(int x, int y) { return (x + y - infMin(x, y)); }
bool infSmaller(int x, int y) {
  if (x == INF) return false;
  if (y == INF) return true;
  return x < y;
}
struct comp_infSmaller {
  bool operator()(pair<int, int> a, pair<int, int> b) {
    if (a.first != b.first) return infSmaller(a.first, b.first);
    return infSmaller(a.second, b.second);
  }
  bool operator()(int x, int y) { return infSmaller(x, y); }
};
struct sum_max_t {
  set<pair<int, int>, comp_infSmaller> entries;
  multiset<int, comp_infSmaller> sums;
  int maxY;
  sum_max_t() : entries(), sums(), maxY(0) {}
  void add(int x, int y) {
    maxY = infMax(maxY, y);
    pair<int, int> ent = pair<int, int>(x, y);
    auto itr = entries.lower_bound(ent);
    if (itr == entries.end() || itr->second < y) {
      bool run = true;
      while (run) {
        auto itr2 = entries.lower_bound(ent);
        if (itr2 == entries.begin()) {
          run = false;
        } else {
          int nextY = (itr2 == entries.end() ? 0 : itr2->second);
          --itr2;
          if (itr2->second < y) {
            sums.erase(sums.find(infAdd(itr2->first, nextY)));
            int currY = itr2->second;
            entries.erase(itr2);
            itr2 = entries.lower_bound(ent);
            if (itr2 != entries.begin()) {
              --itr2;
              sums.erase(sums.find(infAdd(itr2->first, currY)));
              sums.insert(infAdd(itr2->first, nextY));
            }
          } else
            run = false;
        }
      }
      itr = entries.lower_bound(ent);
      int nextY = (itr == entries.end() ? 0 : itr->second);
      if (itr != entries.begin()) {
        --itr;
        sums.erase(sums.find(itr->first + nextY));
        sums.insert(infAdd(itr->first, y));
      }
      entries.insert(ent);
      sums.insert(infAdd(x, nextY));
    }
  }
  int query() { return sums.empty() ? maxY : infMin(*sums.begin(), maxY); }
};
struct triple {
  int arr[3];
  int& operator[](int i) { return arr[i]; }
};
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int> > arrs = vector<vector<int> >(3);
  set<int> allValues = set<int>();
  for (int i = 0; i < 3; i++) {
    arrs[i] = vector<int>(n);
    for (int j = 0; j < n; j++) {
      cin >> arrs[i][j];
      allValues.insert(arrs[i][j]);
    }
  }
  vector<int> valuesArr = vector<int>(allValues.begin(), allValues.end());
  vector<triple> entries = vector<triple>(valuesArr.size());
  for (int i = 0; i < entries.size(); i++)
    for (int j = 0; j < 3; j++) entries[i][j] = INF;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < n; j++) {
      int name = lower_bound(valuesArr.begin(), valuesArr.end(), arrs[i][j]) -
                 valuesArr.begin();
      entries[name][i] = infMin(entries[name][i], j + 1);
    }
  }
  sort(entries.begin(), entries.end(),
       [](triple a, triple b) { return infSmaller(a[0], b[0]); });
  int minU = 0;
  for (int i = (int)entries.size() - 1; i >= 0; i--) {
    if (entries[i][1] == INF && entries[i][2] == INF) {
      minU = entries[i][0];
      break;
    }
  }
  int bestSum = INF;
  int index = entries.size() - 1;
  sum_max_t ds = sum_max_t();
  for (int u = n; u >= minU; --u) {
    while (index >= 0 && infSmaller(u, entries[index][0])) {
      ds.add(entries[index][1], entries[index][2]);
      --index;
    }
    bestSum = infMin(bestSum, infAdd(u, ds.query()));
  }
  cout << bestSum << endl;
  return 0;
}
