Under construction

Still being built. Things may change

Alpha-ville and Beta-ville

Interview

Time limit1sMemory limit512 MB

Summary
Given a waiting list of N numbers and M friend numbers, find the fewest swaps that move every friend ahead of all non-friends.
Level

Easy3 of 10

Topics
Array, Greedy
Solved
No attempts yet

Problem

Minkyu and his friends live in two villas right next to each other, Alpha-ville and Beta-ville. Alpha-ville is a cheap, good villa, so it is very popular and many people line up to move in. Minkyu's friends also have numbers on the Alpha-ville waiting list. Friends who fail to get into Alpha-ville will have to move into the more expensive Beta-ville. Minkyu feels sorry for them and wants to rearrange the waiting list without the landlord noticing, so that more friends can get into Alpha-ville.

The waiting list shows the waiting numbers of the people in the order they will move in, from left to right. The waiting numbers are distinct integers from 11 to NN.

Each time Minkyu changes the list, he can choose two numbers and swap their positions. If he changes the list too often, the landlord may notice, so Minkyu wants to change it as little as possible. Print the minimum number of swaps needed so that all of Minkyu's friends move in before everyone who is not his friend.

Input

The first line contains NN and MM, the number of numbers on the waiting list and the number of Minkyu's friends, separated by a space. (1≤M≤N≤1 0001 \le M \le N \le 1\,000)

The second line contains the NN integers written on the waiting list.

The third line contains MM integers, the waiting numbers of Minkyu's friends.

Output

Print the minimum number of changes needed so that all friends move in first.

Examples2

  1. Example 1

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

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