beecrowd | 2448


By OBI - Olimpíada Brasileira de Informática 2014 BR Brazil

Timelimit: 1

A postman is responsible for giving the orders in the street Joãozinho. On the company policy, orders must be delivered in the same order they were sent, even if that is not the quickest way. Tired of going up and down that road so many times, our friend wants to show the company how long it takes to deliver orders in an attempt to overturn this policy.

Joãozinho's street has N homes. Of course, the houses are numbered in an orderly fashion (not necessarily consecutive numbers). Considering that houses have approximately the same size, you can assume that the postman takes one unit of time to walk from one house to the immediately neighboring house.

There M orders for this street, which should be delivered in the same order in which they arrived. Each order contains the number of the house where it should be delivered.

Write a program that determines how long the postman will take to deliver all orders, assuming that when the time starts ticking, it is the first house (the lower number), and the time finishes telling when all orders were delivered (even if the postman is not back in the first house). You can disregard the time to put the order in the mailbox (that is, if it has only an order, to the first house, the answer to the problem is zero).


The first line contains two integers, N and M (1 ≤ N, M ≤ 45,000), respectively the number of houses and the number of orders. The second line contains N (1 ≤ Ni ≤ 109) integers in strictly ascending order, indicating the numbers of the houses. The third line contains M (1 ≤ Mi ≤ 109) integers indicating the numbers of the houses where the orders are to be delivered, in the order given at the entrance.


Your program should produce a single line containing a single integer, as long as the postman will take to deliver all orders in the correct order, assuming that it starts in the fewest home.

Input Sample Output Sample

5 5

1 5 10 20 40

10 20 10 40 1


3 4

50 80 100

80 80 100 50