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;
struct Node {
  int v, id, from;
} seq[1001000];
int n, a[4][100100], tot, cnt, num[1001000], nnum[1001000], vis[1001000],
    str[4], total[4];
bool viss[1001000], need[4][1001000];
bool cmp(Node x, Node y) { return x.v < y.v; }
void work() {
  tot = 0;
  int ans = 1 << 30;
  for (int u = str[1]; u <= n; u++) {
    if (!need[1][u]) continue;
    memset(vis, 0, sizeof(int) * (cnt + 3));
    tot = 0;
    for (int i = 1; i <= u; i++) tot += !vis[a[1][i]], vis[a[1][i]]++;
    for (int i = 1; i <= n; i++) tot += !vis[a[3][i]], vis[a[3][i]]++;
    int w = n;
    while (w && tot == cnt && vis[a[3][w]] > 1) vis[a[3][w]]--, w--;
    if (tot == cnt) ans = min(ans, u + w);
    for (int v = 1; v <= n; v++) {
      tot += !vis[a[2][v]], vis[a[2][v]]++;
      while (w && tot == cnt && vis[a[3][w]] > 1) vis[a[3][w]]--, w--;
      if (tot == cnt) ans = min(ans, u + v + w);
    }
  }
  cout << ans;
}
void work2() {
  tot = 0;
  int ans = 1 << 30;
  for (int t = 1; t <= 70000000 / n; t++) {
    int u = str[1] + rand() % (n - str[1] + 1);
    if (viss[u] || !need[1][u]) {
      t--;
      continue;
    }
    memset(vis, 0, sizeof(int) * (cnt + 3));
    tot = 0;
    for (int i = 1; i <= u; i++) tot += !vis[a[1][i]], vis[a[1][i]]++;
    for (int i = 1; i <= n; i++) tot += !vis[a[3][i]], vis[a[3][i]]++;
    int w = n;
    while (w && tot == cnt && vis[a[3][w]] > 1) vis[a[3][w]]--, w--;
    if (tot == cnt) ans = min(ans, u + w);
    for (int v = 1; v <= n; v++) {
      tot += !vis[a[2][v]], vis[a[2][v]]++;
      while (w && tot == cnt && vis[a[3][w]] > 1) vis[a[3][w]]--, w--;
      if (tot == cnt) ans = min(ans, u + v + w);
    }
  }
  cout << ans;
}
int main() {
  srand((unsigned)time(NULL));
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[1][i]), seq[++tot] = (Node){a[1][i], i, 1};
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[2][i]), seq[++tot] = (Node){a[2][i], i, 2};
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[3][i]), seq[++tot] = (Node){a[3][i], i, 3};
  sort(seq + 1, seq + tot + 1, cmp);
  a[seq[1].from][seq[1].id] = 1;
  cnt++;
  num[cnt]++;
  for (int i = 2; i <= tot; i++) {
    if (seq[i].v != seq[i - 1].v) cnt++;
    a[seq[i].from][seq[i].id] = cnt;
    num[cnt]++;
  }
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= cnt; j++) nnum[j] = num[j];
    for (int j = n; j >= 1; j--) {
      nnum[a[i][j]]--;
      if (!nnum[a[i][j]]) {
        str[i] = j;
        break;
      }
    }
  }
  for (int i = 1; i <= 3; i++) {
    memset(vis, 0, sizeof(vis));
    for (int j = 1; j <= n; j++)
      if (!vis[a[i][j]]) {
        vis[a[i][j]] = 1, need[i][j] = 1;
        if (j >= str[i]) total[i]++;
      }
    if (!need[i][str[i]]) total[i]++, need[i][str[i]] = 1;
  }
  for (int i = 2; i <= 3; i++)
    if (total[i] < total[1]) {
      swap(str[i], str[1]);
      swap(total[i], total[1]);
      for (int j = 1; j <= n; j++)
        swap(a[i][j], a[1][j]), swap(need[i][j], need[1][j]);
    }
  if ((long long)n * total[1] <= 70000000)
    work();
  else
    work2();
}
