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 bit = 17;
int skew[2 << bit];
int least[2 << bit];
void update(int update_to, int value, int root, int step) {
  if (update_to < 0) return;
  if (update_to >= step - 1) {
    least[root] = max(least[root], value);
    skew[root] = max(skew[root], least[root]);
    return;
  }
  update(update_to, value, root * 2, step / 2);
  update(update_to - step / 2, value, root * 2 + 1, step / 2);
  skew[root] = max(skew[root * 2], skew[root * 2 + 1] + step / 2);
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  map<int, vector<int> > aa, bb, cc;
  map<int, int> occ;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    aa[a[i]].push_back(i);
    occ[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    bb[b[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    cc[c[i]].push_back(i);
    occ[c[i]]++;
  }
  for (int i = 0; i < (1 << bit); i++) skew[(1 << bit) + i] = 10 * n;
  int now = n;
  for (int i = 0; i <= n; i++) {
    while (now > 0 && occ[c[now - 1]] > 1) {
      occ[c[now - 1]]--;
      now--;
    }
    skew[(1 << bit) + i] = now;
    if (i == n) break;
    occ[b[i]]++;
  }
  for (int layer = bit - 1; layer >= 0; layer--) {
    int step = (1 << (bit - layer - 1));
    for (int i = (1 << layer); i < (2 << layer); i++) {
      skew[i] = min(skew[i * 2], skew[i * 2 + 1] + step);
    }
  }
  int res = skew[1] + n;
  for (int i = n - 1; i >= 0; i--) {
    if (aa[a[i]][0] == i) {
      bool b_present = (bb.find(a[i]) != bb.end());
      bool c_present = (cc.find(a[i]) != cc.end());
      if (!b_present && !c_present) break;
      int update_to = n;
      if (b_present) update_to = bb[a[i]][0];
      int value = n * 10;
      if (c_present) value = cc[a[i]][0] + 1;
      update(update_to, value, 1, 1 << bit);
    }
    res = min(res, skew[1] + i);
  }
  printf("%d\n", res);
}
