Under construction

Still being built. Things may change

Colorful Chain

Interview

Time limit3sMemory limit512 MB

Summary
Count the contiguous segments that hold exactly the required number of links of each listed color and no other colors.
Level

Medium4 of 10

Topics
Sliding window, Hash map, Array
Solved
No attempts yet

Problem

Bytie loves playing with colorful chains. He already owns quite a collection, and he likes some of them more than others. A chain is a row of colored links.

Byteasar has noticed that Bytie's taste is very precise. Bytie calls a contiguous fragment of a chain nice if it contains exactly l1l_1 links of color c1c_1, exactly l2l_2 links of color c2c_2, …\dots, exactly lml_m links of color cmc_m, and no links of any other color. The appeal of a chain is the number of nice contiguous fragments it contains.

After many attempts Byteasar worked out the values c1,…,cmc_1, \dots, c_m and l1,…,lml_1, \dots, l_m. He now wants to buy a new chain, so he asks you for a program that helps him shop.

Input

The first line contains two integers nn and mm separated by a single space (1≤m≤n≤1 000 0001 \le m \le n \le 1\,000\,000): the length of the chain and the length of the description of a nice fragment.

The second line contains mm integers l1,…,lml_1, \dots, l_m separated by single spaces (1≤li≤n1 \le l_i \le n).

The third line contains mm integers c1,…,cmc_1, \dots, c_m separated by single spaces (1≤ci≤n1 \le c_i \le n, and ci≠cjc_i \ne c_j whenever i≠ji \ne j).

The sequences l1,…,lml_1, \dots, l_m and c1,…,cmc_1, \dots, c_m define a nice fragment: it has to contain exactly lil_i links of color cic_i.

The fourth line contains nn integers a1,…,ana_1, \dots, a_n separated by single spaces (1≤ai≤n1 \le a_i \le n), the colors of the successive links of the chain.

Output

Print a single integer, the number of nice contiguous fragments in the chain.

Hint

In the first example the nice fragments are 2 1 3 1 and 1 3 1 2, so the answer is 2.

Examples1

  1. Example 1

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