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;
inline int read() {
  int res = 0;
  int neg;
  while (true) {
    char ch = getchar();
    if (ch >= '0' && ch <= '9' || ch == '-') {
      if (ch == '-')
        neg = -1;
      else
        neg = 1, res = ch - '0';
      break;
    }
  }
  while (true) {
    char ch = getchar();
    if (ch >= '0' && ch <= '9')
      res *= 10, res += ch - '0';
    else
      break;
  }
  return res * neg;
}
const int maxn = 1000020;
const int maxm = 1020;
const int MOd = 1e9 + 7;
int a, n, ar[3][maxn], lazy[maxn * 3], segment[maxn * 3], segment2[maxn];
map<int, int> mp[4];
vector<pair<int, int> > v[maxn];
void ind(int k, int b) {
  if (lazy[k]) {
    if (k < n) {
      lazy[k + k] = lazy[k];
      lazy[k + k + 1] = lazy[k];
    }
    segment[k] = lazy[k] + b;
    lazy[k] = 0;
  }
}
int update(int k, int b, int s, int x, int y, int m) {
  ind(k, b);
  if (b > y || x > s) return segment[k];
  if (x <= b && s <= y) {
    lazy[k] = m;
    segment2[k] = m;
    ind(k, b);
    return segment[k];
  }
  segment[k] =
      min(update(k + k, b, (((b + s) < 0) ? (b + s) / 2 - 1 : (b + s) / 2), x,
                 y, m),
          update(k + k + 1, (((b + s) < 0) ? (b + s) / 2 - 1 : (b + s) / 2) + 1,
                 s, x, y, m));
  return segment[k];
}
int look(int k) {
  int t = 0;
  k += n;
  for (; k; k >>= 1) t = max(t, (segment2[k]));
  return t;
}
int main() {
  scanf("%d", &a);
  n = 1;
  while (n < a + 2) n <<= 1;
  for (int i = 0; i <= a; i++) segment[i + n] = i;
  for (int i = a + 1; i < n; i++) segment[i + n] = 1e9;
  for (int i = n - 1; i >= 1; i--)
    segment[i] = min(segment[i + i], segment[i + i + 1]);
  for (int i = 1; i <= a; i++) scanf("%d", &ar[0][i]);
  for (int i = 1; i <= a; i++) scanf("%d", &ar[1][i]);
  for (int i = 1; i <= a; i++) scanf("%d", &ar[2][i]);
  for (int i = a; i >= 1; i--) mp[0][ar[0][i]] = i, mp[3][ar[0][i]] = 1;
  for (int i = a; i >= 1; i--) mp[1][ar[1][i]] = i, mp[3][ar[1][i]] = 1;
  for (int i = a; i >= 1; i--) mp[2][ar[2][i]] = i, mp[3][ar[2][i]] = 1;
  for (map<int, int>::iterator it = mp[3].begin(); it != mp[3].end(); it++) {
    int p = a + 1;
    if (mp[0].count(it->first)) p = mp[0][it->first];
    if (!mp[1].count(it->first)) mp[1][it->first] = a + 1;
    if (!mp[2].count(it->first)) mp[2][it->first] = 1e9;
    v[p].push_back(pair<int, int>(mp[1][it->first], mp[2][it->first]));
  }
  int ans = 1e9;
  for (int i = a; i >= 0; i--) {
    for (int j = 0; j < v[i + 1].size(); j++) {
      int t = v[i + 1][j].first, h = look(v[i + 1][j].first);
      if (h >= v[i + 1][j].second) continue;
      for (int k = 17; k >= 0; k--)
        if ((1 << k) <= t && look(t - (1 << k)) < v[i + 1][j].second)
          t -= 1 << k;
      update(1, 0, n - 1, t, v[i + 1][j].first - 1, v[i + 1][j].second);
    }
    ans = min(ans, (segment[1] + i));
  }
  printf("%d\n", ans);
  return 0;
}
