Under construction

Still being built. Things may change

Photoshoot 2

Interview

Time limit2sMemory limit1024 MB

Summary
Given a start permutation and a target permutation, count the fewest cows you must move left (one at a time) to reach the target order.
Level

Medium5 of 10

Topics
Array, Greedy, Hash map, Two pointers
Solved
No attempts yet

Problem

In what seems to be a familiar occurrence, Farmer John is lining up his NN cows (1≤N≤1051\le N\le 10^5), conveniently numbered 1…N1\ldots N, for a photograph.

Initially, the cows are lined up in the order a_1,a_2,…,a_Na\_1,a\_2,\ldots,a\_N from left to right. Farmer John's goal is to line up the cows in the order b_1,…,b_Nb\_1,\ldots,b\_N from left to right. To accomplish this, he may perform a series of modifications to the ordering. Each modification consists of choosing a single cow and moving it some number of positions to the left.

Please count the minimum number of modifications required in order for Farmer John to line up his cows in the desired order.

Input

The first line of input contains NN. The second line contains a_1,a_2,…,a_Na\_1,a\_2,\ldots,a\_N. The third line contains b_1,…,b_Nb\_1,\ldots,b\_N.

Output

Print the minimum number of modifications required to produce Farmer John's desired ordering.

Examples2

  1. Example 1

    Input
    5
    1 2 3 4 5
    1 2 3 4 5
    
    Expected output
    0
    
  2. Example 2

    Input
    5
    5 1 3 2 4
    4 5 2 1 3
    
    Expected output
    2