#B4098. Minimum Ticket Cost to See All Animals

    ID: 11755 Type: Default 1000ms 256MiB

Minimum Ticket Cost to See All Animals

Minimum Ticket Cost to See All Animals

A zoo has nn venues numbered 1,2,,n1,2,\dots,n and mm animal types numbered 1,2,,m1,2,\dots,m (with mnm \le n). Each venue houses exactly one animal, although different venues may house the same species.\n\nThe ticketing system is special: when buying a ticket, a visitor must specify a starting venue aa and an ending venue bb. The printed ticket shows these two numbers, and the visitor is only allowed to visit venues aa through bb (inclusive). The cost is calculated as $$10 \times (b - a + 1).$$\n\nLittle Ming wants to see all mm animal types while spending as little as possible. However, he can only purchase one ticket. Determine the minimum amount of money he must spend to see all animal types (it is acceptable to see the same type more than once).

inputFormat

The input consists of two lines:\ The first line contains two integers nn and mm (1mn1 \le m \le n).\ The second line contains nn integers, where the ii-th integer represents the animal type at venue ii (an integer between 11 and mm).

outputFormat

Output a single integer representing the minimum ticket cost required to visit a contiguous block of venues that includes all mm animal types.

sample

8 3
1 2 3 1 2 3 2 1
30