Aquarium Arrangement
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

    You are an employee at the Benelux Aquarium for Piranhas and Catfifish. The aquarium is hoping to ex-pand its meagre selection of aquatic life, but lacks the funds to do so. You have been tasked to help promote the aquarium by taking photos of the two exhibits.Taking the fifirst photo went swimmingly, because the catfifish were very cooperative. For the piranhas, you have an arrangement of piranhas in mind that will look great on the photo. However, the only way to get the piranhas to move is by recklessly sticking your fifinger into the water to lure the piranhas. Your goal is to move the piranhas to the desired positions as quickly as possible without losing your fifinger in the process.
The piranha exhibit can be divided into positions 1, . . . , n from left to right. The exhibit contains k piranhas and every position is occupied by at most one piranha. You can stick your fifinger into any unoccupied position. This will lure the nearest piranha to the left of your fifinger and the nearest piranha to the right of your fifinger. These piranhas will swim towards your fifinger, moving forward one position per second. All other piranhas simply stay in place.A piranha will bite your fifinger if it reaches the same position, so you must pull your fifinger away before this happens. Pulling your fifinger away and sticking it into a difffferent position does not take any time.
    For example, suppose there are piranhas at positions 2, 7 and 9. If you stick your fifinger into the water at position 4, the piranhas will be at positions 3, 6 and 9 after one second. You now have to pull your fifinger away to prevent the piranha at position 3 from biting your fifinger one second later. If you now stick your fifinger into the water at position 1, only the piranha at position 3 will move and will end up at position 2 after one second.

输入描述:

The input consists of:
    • One line containing two integers n (1 ≤ n ≤ 1000), the number of positions, and k(1 ≤ k ≤ n), the number of piranhas.
    • One line containing k integers 1 ≤ p1 < . . . < pk ≤ n, the current positions of the piranhas.
    • One line containing k integers 1 ≤ d1 < . . . < dk ≤ n, the desired positions of the piranhas.

输出描述:

Output the minimum number of seconds needed to get all of the piranhas at the desired positions. If it is impossible to do so, output “impossible”.
示例1

输入

复制
9 3
3 7 9
3 5 9

输出

复制
4
示例2

输入

复制
8 3
1 5 8
2 4 7

输出

复制
impossible
示例3

输入

复制
20 6
1 4 7 10 13 20
2 5 8 11 14 17

输出

复制
17