Painting

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

You have been hired to paint a fence. The fence consists of nn sections, numbered 11 through nn. The fence is required to be eventually painted using mm colors, numbered 11 through mm. For each section ii, the desired color c_ic\_i of that section is known.

Your order also specifies how the painting process should look like. The painting should be conducted in exactly mm phases. In each phase, you can pick some color c1,,mc\in\\{1,\ldots,m\\} and two indices a,ba,b, 1abn1\leq a\leq b\leq n, and paint the segments a,a+1,,ba,a+1,\ldots,b with color cc. It takes ba+1b-a+1 hours to perform such a phase. If some of these segments has been painted before, the previous color is replaced with cc. Initially, all segments are unpainted.

Is is guaranteed that it is possible to paint the fence as required using the above process. However, you are free to decide how the individual phases will look like. Since you are paid hourly, you would like the painting to take as much time as possible.

Consider the following example. Let n=4n=4, m=3m=3 and suppose the subsequent segments have to be painted with colors (2,1,2,3)(2, 1, 2, 3). We could paint the fence so that the colors change as follows (here, 00 denotes unpainted): (0,0,0,0)(0,0,0,3)(2,2,2,3)(2,1,2,3).(0, 0, 0, 0)\to (0, 0, 0, 3)\to (2, 2, 2, 3)\to (2, 1, 2, 3). Such a painting takes 1+3+1=51+3+1=5 hours. However, we could also spend 88 hours (ans thus earn more money) if we proceeded as follows: (0,0,0,0)(3,3,3,3)(2,2,2,3)(2,1,2,3).(0, 0, 0, 0)\to (3, 3, 3, 3)\to (2, 2, 2, 3)\to (2, 1, 2, 3).

Compute the maximum possible painting time.

입력

The first line of the input contains two integers nn, mm (1n1051\leq n\leq 10^5, 1m50001\leq m\leq 5000), denoting the number of the fence's segments and the number of used colors. The second line of the input contains nn integers c_1,,c_nc\_1,\ldots,c\_n (1c_im1\leq c\_i\leq m) that describe the desired colors of individual segments. It is guaranteed that each of the mm colors appears at least once in that sequence, i.e., c_1,,c_n=1,,m\\{c\_1,\ldots,c\_n\\}=\\{1,\ldots,m\\}.

출력

You should output the maximum possible painting time when painting according to the described rules.