#P1767E. Algebra Flash

    ID: 475 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 9 Uploaded By: Tags>bitmasksbrute forcedpgraphsmathmeet-in-the-middletrees*2500

Algebra Flash

Description

Algebra Flash 2.2 has just been released!

Changelog:

  • New gamemode!

Thank you for the continued support of the game!

Huh, is that it? Slightly disappointed, you boot up the game and click on the new gamemode. It says "Colored platforms".

There are nn platforms, numbered from 11 to nn, placed one after another. There are mm colors available in the game, numbered from 11 to mm. The ii-th platform is colored cic_i.

You start on the platform 11 and want to reach platform nn. In one move, you can jump from some platform ii to platforms i+1i + 1 or i+2i + 2.

All platforms are initially deactivated (including platforms 11 and nn). For each color jj, you can pay xjx_j coins to activate all platforms of that color.

You want to activate some platforms so that you could start on an activated platform 11, jump through some activated platforms and reach an activated platform nn.

What's the smallest amount of coins you can spend to achieve that?

The first line contains two integers nn and mm (2n31052 \le n \le 3 \cdot 10^5; 1m401 \le m \le 40) — the number of platforms and the number of colors, respectively.

The second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n (1cim1 \le c_i \le m) — the colors of the platforms.

The third line contains mm integers x1,x2,,xmx_1, x_2, \dots, x_m (1xi1071 \le x_i \le 10^7) — the cost of activating all platforms of each color.

Print the smallest amount of coins you can spend to activate some platforms so that you could start on an activated platform 11, jump through some activated platforms and reach an activated platform nn.

Input

The first line contains two integers nn and mm (2n31052 \le n \le 3 \cdot 10^5; 1m401 \le m \le 40) — the number of platforms and the number of colors, respectively.

The second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n (1cim1 \le c_i \le m) — the colors of the platforms.

The third line contains mm integers x1,x2,,xmx_1, x_2, \dots, x_m (1xi1071 \le x_i \le 10^7) — the cost of activating all platforms of each color.

Output

Print the smallest amount of coins you can spend to activate some platforms so that you could start on an activated platform 11, jump through some activated platforms and reach an activated platform nn.

Sample Input 1

5 3
1 3 2 3 1
1 10 100

Sample Output 1

11

Sample Input 2

5 3
1 3 2 3 1
1 200 20

Sample Output 2

21

Sample Input 3

4 2
2 2 1 1
5 5

Sample Output 3

10

Sample Input 4

10 10
3 8 6 2 10 5 2 3 7 3
9 7 4 2 1 8 2 6 2 2

Sample Output 4

15