Permutation
题号:NC219808
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

You are given two permutations and of length .
A permutation is a sequence of length integers from to , in which all the numbers occur exactly once. For example, are permutations, and are not.
There are two types of operations as follow:
  • Remove the first integer in . Then append any integer at the end of .
  • Choose an and modify it to any integer.
You have to find the minimum number of operations to make and the same.
Be attention, you do not have to keep in a permutation during the process.

输入描述:

The first line contains an integer  — the length of  and  .
The second line contains integers .
The third line contains integers .
It is guaranteed that and are both permutations.

输出描述:

Output the minimum number of operations to make  and  the same.
示例1

输入

复制
5
5 2 3 4 1
5 3 2 1 4

输出

复制
3

说明

For the first example, there is a possible way:
1. Remove the first integer in a_{} and append 4, now a_{} becomes [2,3,4,1,4]_{}.
2. modify a_1 to 5_{}, now a_{} becomes [5,3,4,1,4]_{}.
3. modify a_3 to 2_{}, now a_{} becomes [5,3,2,1,4]_{}.
So it only takes 3_{} operations to convert a_{} into b_{}.