You have decided to watch the best moments of some movie. There are two buttons on your player: 
 1.  Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1.  Skip exactly *x* minutes of the movie (*x* is some fixed positive integer). If the player is now at the *t*-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (*t* + *x*). 
Initially the movie is turned on in the player on the first minute, and you want to watch exactly *n* best moments of the movie, the *i*-th best moment starts at the *l*<sub class="lower-index">*i*</sub>-th minute and ends at the *r*<sub class="lower-index">*i*</sub>-th minute (more formally, the *i*-th best moment consists of minutes: *l*<sub class="lower-index">*i*</sub>, *l*<sub class="lower-index">*i*</sub> + 1, ..., *r*<sub class="lower-index">*i*</sub>). 

Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?
The first line contains two space-separated integers *n*, *x* (1 ≤ *n* ≤ 50, 1 ≤ *x* ≤ 10<sup class="upper-index">5</sup>) — the number of the best moments of the movie and the value of *x* for the second button.

The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains two integers separated by a space *l*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub> (1 ≤ *l*<sub class="lower-index">*i*</sub> ≤ *r*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>).

It is guaranteed that for all integers *i* from 2 to *n* the following condition holds: *r*<sub class="lower-index">*i* - 1</sub> &lt; *l*<sub class="lower-index">*i*</sub>.
# Read n (number of best moments) and x (skip duration) from input
n, x = map(int, input().split())

# Initialize total_time to keep track of total minutes watched
total_time = 0

# Initialize current_time to keep track of the current minute
current_time = 1

# Loop through each of the n best moments
for _ in range(n):
    # Read the start and end minutes of the current best moment
    l, r = map(int, input().split())
    
    # Calculate the time needed to reach the start of the current best moment
    time_to_start = (l - current_time) % x
    
    # Calculate the time needed to watch the entire best moment
    time_to_watch = r - l + 1
    
    # Update total_time by adding time_to_start and time_to_watch
    total_time += time_to_start + time_to_watch
    
    # Update current_time to the minute following the end of the current best moment
    current_time = r + 1

# Print the total_time, which represents the minimum number of minutes to watch all best moments
print(total_time)
