CSES - Freight
  • Time limit: 1.00 s
  • Memory limit: 128 MB

The train stations in Upper Bytown and Lower Bytown are connected with a single track rail link. It takes the train s minutes to travel between them in either direction. However, the trains departing a station have to be spaced at least one minute apart. Moreover, at all times, all the trains on the rail link have to go in the same direction.

According to the timetable at our disposal, n cargo trains destined for Lower Bytown are to pass through the Upper Bytown. They are to be loaded with goods in Lower Bytown and then return to Upper Bytown. For simplicity, we assume that loading the goods on the train takes virtually no time.

We are to determine the minimum possible time of the last train returning to Upper Bytown.

Input

The first line of the standard input contains two integers n, s, separated by a single space, that specify the number of trains and the one-way travel time respectively. The second line contains n integers t_1, t_2, \ldots, t_n, separated by a single space, that specify the arrival times of successive trains at the Upper Bytown station.

Output

Your program should print out a single line with a single integer to the standard output: the minimum possible time of the last train returning to Upper Bytown.

Constraints

  • 1 \le n \le 10^6
  • 1 \le s \le 10^9
  • 0 \le t_1 \le t_2 \le \ldots \le t_n \le 10^9

Example

For the input data:

3 4
1 8 11

the correct result is:

20

Explanation: To attain the minimum time, the trains can depart from Upper Bytown at times 1, 9, and 11, and from Lower Bytown at times 5, 15, and 16.

Task author: Michal Wlodarczyk.