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>
#pragma warning(disable : 4996)
using namespace std;
int n;
long long a[3][200000];
set<int> w[3];
long long f[3][200000];
map<int, int> inv[3];
set<pair<int, int> > gset;
multiset<int> sum;
int graph[200000];
pair<int, int> q[200000];
int qi;
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < 3; i++) {
    for (j = 0; j < n; j++) scanf("%I64d", &a[i][j]);
  }
  for (i = 0; i < 3; i++) {
    for (j = 0; j < n; j++) {
      if (!w[i].count(a[i][j])) {
        w[i].insert(a[i][j]);
        f[i][j] = 1;
        inv[i][a[i][j]] = j;
      }
    }
  }
  int start = 0;
  for (i = n - 1; i >= 0; i--) {
    if (f[2][i] == 0) continue;
    if (w[0].count(a[2][i]) || w[1].count(a[2][i])) continue;
    start = i + 1;
    break;
  }
  graph[n] = start;
  for (i = n - 1; i >= 0; i--) {
    if (f[1][i] == 0 || inv[0].count(a[1][i])) {
      graph[i] = graph[i + 1];
    } else {
      if (!inv[2].count(a[1][i])) {
        graph[i] = 1000000;
      } else {
        if (inv[2][a[1][i]] <= start - 1) {
          graph[i] = graph[i + 1];
        } else
          graph[i] = inv[2][a[1][i]] + 1;
      }
    }
  }
  for (i = 0; i <= n; i++) {
    if (graph[i] != graph[i + 1] || i == n) {
      gset.insert(pair<int, int>(i, graph[i]));
    }
  }
  gset.insert(pair<int, int>(-1, 1000000));
  for (auto it : gset) {
    set<pair<int, int> >::iterator z =
        gset.upper_bound(pair<int, int>(it.first, 1000000));
    if (z == gset.end()) break;
    sum.insert(it.first + 1 + z->second);
  }
  int minn = *sum.begin() + n;
  for (i = n - 1; i >= 0; i--) {
    if (f[0][i] == 0) {
      if (minn > *sum.begin() + i) {
        minn = *sum.begin() + i;
      }
      continue;
    }
    int x, y;
    if (!inv[1].count(a[0][i]))
      x = 1000000;
    else
      x = inv[1][a[0][i]] + 1;
    x--;
    if (!inv[2].count(a[0][i]))
      y = 1000000;
    else
      y = inv[2][a[0][i]] + 1;
    set<pair<int, int> >::iterator z = gset.lower_bound(pair<int, int>(x, -1));
    if (z != gset.end() && z->second >= y) {
      if (minn > *sum.begin() + i) {
        minn = *sum.begin() + i;
      }
      continue;
    }
    z--;
    qi = 0;
    while (1) {
      set<pair<int, int> >::iterator u =
          gset.upper_bound(pair<int, int>(z->first, 1000000));
      if (u != gset.end()) sum.erase(sum.find(z->first + 1 + u->second));
      if (z->second >= y) break;
      q[qi++] = *z;
      if (z == gset.begin()) break;
      z--;
    }
    for (j = 0; j < qi; j++) gset.erase(q[j]);
    set<pair<int, int> >::iterator u;
    gset.insert(pair<int, int>(x, y));
    z = gset.find(pair<int, int>(x, y));
    u = gset.upper_bound(pair<int, int>(z->first, 1000000));
    if (u != gset.end()) sum.insert(z->first + 1 + u->second);
    z = gset.lower_bound(pair<int, int>(x, -1));
    if (z != gset.begin()) {
      z--;
      u = gset.upper_bound(pair<int, int>(z->first, 1000000));
      if (u != gset.end()) sum.insert(z->first + 1 + u->second);
    }
    if (x == 1000000 && y == 1000000) break;
    if (minn > *sum.begin() + i) {
      minn = *sum.begin() + i;
    }
  }
  printf("%d", minn);
  return 0;
}
