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 MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
const int maxn = 100000 + 10;
int n;
int a[maxn];
int b[maxn];
int c[maxn];
int fa[maxn];
int fb[maxn];
int fc[maxn];
int cnt[3 * maxn];
vector<int> v;
int st[maxn << 2];
int mx[maxn << 2];
int lz[maxn << 2];
void build(int p, int L, int R) {
  if (L == R) {
    st[p] = L;
    return;
  }
  build(p << 1, L, L + R >> 1);
  build(p << 1 | 1, (L + R >> 1) + 1, R);
  st[p] = min(st[p << 1], st[p << 1 | 1]);
}
void updlz(int p, int L, int R) {
  if (lz[p]) {
    chkmax(mx[p], lz[p]);
    st[p] = mx[p] + L;
    if (L < R) {
      chkmax(lz[p << 1], lz[p]);
      chkmax(lz[p << 1 | 1], lz[p]);
    }
    lz[p] = 0;
  }
}
void upd(int p, int l, int r, int L, int R, int val) {
  updlz(p, L, R);
  if (l > R || r < L) return;
  if (l <= L && r >= R) {
    lz[p] = val;
    updlz(p, L, R);
    return;
  }
  upd(p << 1, l, r, L, L + R >> 1, val);
  upd(p << 1 | 1, l, r, (L + R >> 1) + 1, R, val);
  st[p] = min(st[p << 1], st[p << 1 | 1]);
}
int query(int p, int l, int r, int L, int R) {
  updlz(p, L, R);
  if (l > R || r < L) return INF;
  if (l <= L && r >= R) return st[p];
  return min(query(p << 1, l, r, L, L + R >> 1),
             query(p << 1 | 1, l, r, (L + R >> 1) + 1, R));
}
int rmq[maxn];
int upd(int p, int n, int val) {
  for (chkmax(rmq[p += n], val); p > 1;)
    p >>= 1, rmq[p] = max(rmq[p << 1], rmq[p << 1 | 1]);
}
int query(int l, int r, int n) {
  int res = 0;
  for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
    if (l & 1) chkmax(res, rmq[l++]);
    if (r & 1) chkmax(res, rmq[--r]);
  }
  return res;
}
void insert(int x, int y) {
  if (query(x, n + 1, n + 2) >= y) return;
  int l = 0, r = x;
  while (l < r) {
    int m = l + r >> 1;
    if (query(m, x, n + 2) >= y) {
      l = m + 1;
    } else {
      r = m;
    }
  }
  upd(x, n + 2, y);
  upd(1, l, x, 0, n + 1, y);
}
int calc() {
  int res = INF;
  for (int i = (0); i < (n); i++) cnt[a[i]]++;
  build(1, 0, n + 1);
  for (int i = (0); i < (int((v).size())); i++)
    if (!cnt[i]) {
      int x = fb[i];
      int y = fc[i];
      if (!x && !y) {
        return res;
      } else if (!x) {
        insert(n + 1, y);
      } else if (!y) {
        insert(x - 1, INF);
      } else {
        insert(x - 1, y);
      }
    }
  chkmin(res, st[1] + n);
  for (int i = (n)-1; i >= (0); i--) {
    if (!(--cnt[a[i]])) {
      int x = fb[a[i]];
      int y = fc[a[i]];
      if (!x && !y) {
        return res;
      } else if (!x) {
        insert(n + 1, y);
      } else if (!y) {
        insert(x - 1, INF);
      } else {
        insert(x - 1, y);
      }
    }
    chkmin(res, st[1] + i);
  }
  return res;
}
void solve() {
  cin >> n;
  for (int i = (0); i < (n); i++) cin >> a[i], v.push_back(a[i]);
  for (int i = (0); i < (n); i++) cin >> b[i], v.push_back(b[i]);
  for (int i = (0); i < (n); i++) cin >> c[i], v.push_back(c[i]);
  sort((v).begin(), (v).end()),
      (v).erase(unique((v).begin(), (v).end()), (v).end());
  for (int i = (0); i < (n); i++) {
    a[i] = lower_bound((v).begin(), (v).end(), a[i]) - v.begin();
    b[i] = lower_bound((v).begin(), (v).end(), b[i]) - v.begin();
    c[i] = lower_bound((v).begin(), (v).end(), c[i]) - v.begin();
  }
  for (int i = (0); i < (n); i++) {
    if (!fa[a[i]]) {
      fa[a[i]] = i + 1;
    }
    if (!fb[b[i]]) {
      fb[b[i]] = i + 1;
    }
    if (!fc[c[i]]) {
      fc[c[i]] = i + 1;
    }
  }
  cout << calc() << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
