The JOI Art Museum has N paintings displayed in a single horizontal row. There are M types of paintings in the exhibition, numbered from 1 to M. The type of the i-th painting from the left (1 ≦ i ≦ N) is Ai, and its value is Vi. Note that Vi can be negative.
Next month, the JOI Art Museum is scheduled to hold the "EGOI Exhibition 2022." Since many visitors are expected, the museum wants to improve the visual appeal of the display. Therefore, the director, Rie, decided to remove some paintings so that no two adjacent paintings are of the same type.
On the other hand, to enhance the museum's reputation, she wants to maximize the total value of the remaining paintings.
Given the number of paintings, the number of painting types, and the information for the N paintings, write a program to find the maximum possible total value of the remaining paintings.
The input is given from standard input in the following format.
N
M
A1 V1
A2 V2
:
AN VN
Output the maximum possible total value of the remaining paintings in one line to standard output.
3 1 1 107 1 123 1 100
123
If only the 2nd painting from the left is kept, the total value is V2 = 123.
4 3 1 204 2 168 2 277 1 219
700
It is optimal to keep the 1st, 3rd, and 4th paintings from the left.
3 2 1 5 2 -1 1 5
9
It is optimal to keep all the paintings.
6 4 1 -123 2 -123 3 -123 4 -123 4 -123 3 -123
0
It is optimal to keep no paintings at all.
30 4 2 -1358 4 -1405 4 2003 3 -1148 2 -1527 2 -2015 4 -2910 1 2133 2 2185 1 2249 3 1058 1 -1907 2 -3190 1 -2701 3 -2640 1 1685 3 1855 4 2398 3 -3158 2 1947 3 2947 2 -2197 4 1398 2 -3011 4 -1971 1 -2829 1 3094 2 2704 4 -2592 3 2910
30566
Japan Olympiad in Informatics Committee "Japan Olympiad in Informatics 2nd Women's Division Finals Problem"