You have decided to watch the best moments of some movie. There are two buttons on your player:   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.  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_{i}-th minute and ends at the r_{i}-th minute (more formally, the i-th best moment consists of minutes: l_{i}, l_{i} + 1, ..., r_{i}). 

Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?


-----Input-----

The first line contains two space-separated integers n, x (1 ≤ n ≤ 50, 1 ≤ x ≤ 10^5) — 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_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 10^5).

It is guaranteed that for all integers i from 2 to n the following condition holds: r_{i} - 1 < l_{i}.


-----Output-----

Output a single number — the answer to the problem.


-----Examples-----
Input
2 3
5 6
10 12

Output
6

Input
1 1
1 100000

Output
100000



-----Note-----

In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie.

In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.

Difficulty: interview

Starter code:

Solutions:
n, x = list(map(int, input().split()))
result = 0
cur = 1
for i in range(n):
    l, r = list(map(int, input().split()))
    result += r - l + 1
    result += (l - cur) % x
    cur = r + 1
print(result)


[n, x], cur, ans = list(map(int, input().split())), 1, 0
for i in range(n):
	l, r = list(map(int, input().split()))
	cur += (l - cur) // x * x
	ans += r - cur + 1
	cur = r + 1
print(ans)


# A

l = input().split()
n = int(l[0])
x = int(l[1])
curr = 1
tot = 0
for i in range(n):
    p = input().split()
    l = int(p[0])
    r = int(p[1])
    while curr + x <= l:
        curr += x
    tot += r-curr+1
    curr = r+1
print(tot)


n,x = [int(i) for i in input().split()]
t = 1
k = 0
for i in range(n):
    l, r = [int(y) for y in input().split()]
    while(t+x<=l):
        t+=x
    k+=r-t+1
    t = r + 1
print(k)

        


inp = input().split(' ')
num = int(inp[0])
skip = int(inp[1])
out = 0
curr = 1
for x in range(num):
    time = input().split(' ')
    start = int(time[0])
    end = int(time[1])
    while curr + skip <= start:
        curr += skip
    out += end - curr
    out += 1
    curr = end + 1
print(out)


#input

n,x=list(map(int,input().split()))
m=[]
for i in range(n):
	m.append([int(x) for x in input().split()])



#variables
r=1
t=0



#main

for i in range(n):
	t+=(m[i][0]-r)%x+m[i][1]-m[i][0]+1
	r=(m[i][1]+1)%x



#output
print(t)


def movie():
    n, x= [int(i) for i in input().split()]
    ans= 0
    last= 0
    for i in range(n):
        start, end= [int(p) for p in input().split()]
        ans+= (start-last-1)%x
        ans+= end- start+ 1
        last= end
    
    print(ans)
    return

movie()

import sys

n,x = (int(x) for x in input().split(" "))

cur = 1
count = 0

for i in range(0,n):
    l,r = (int(x) for x in input().split(" "))
    while cur+x <= l:
        cur += x
    count += r-cur+1
    cur = r+1
print(count)




n, x = map(int, input().split())
arr = []
for _ in range(n):
	l, r = map(int, input().split())
	arr.append((l,r))
res = 0
res += (arr[0][0]-1)%x
for i in range(n-1):
	res += arr[i][1]-arr[i][0]+1
	res += (arr[i+1][0]-(arr[i][1]+1)) % x
res += arr[n-1][1]-arr[n-1][0]+1
print(res)

n, x = [int(_) for _ in input().split()]
t = 1
c = 0
for m in range(n):
    l, r = [int(_) for _ in input().split()]
    while t <= l:
        t += x
    t -= x
    c += r - t + 1
    t = r + 1
print(c)


'''from math import *
int(input())
list(map(int,input().split()))'''
def main():
	n, x = list(map(int,input().split()))
	time = 0

	for _ in range(n):
		l, r = list(map(int,input().split()))
		if _ == 0:
			curr = 1
		time += (l - curr) % x + (r - l + 1)
		curr = r+1
	print(time)


def __starting_point():
	main()


__starting_point()

def main():
    n, x = list(map(int, input().split()))
    tot, t = 0, 1
    for _ in range(n):
        l, r = list(map(int, input().split()))
        t1 = r
        r -= t - 1
        l -= t
        tot += r - l + l % x
        t = t1 + 1
    print(tot)


def __starting_point():
    main()

__starting_point()

first_line = list(map(int, input().split(' ')))
number_moments = first_line[0]

x_val = first_line[1]

moments = []
for i in range(number_moments):
	moments.append( list(map(int, input().split(' ')) ))
#print(moments)

current_time = 1
watched = 0
for m in moments:
	remaining = m[0] - current_time
	skippable = remaining//x_val
	#print( skippable )
	current_time += x_val * skippable
	watched += m[1] - current_time + 1
	#print(watched)
	current_time = m[1] + 1
print(watched)

n,x=map(int,input().split())

nach=1
summa=0

for i in range(n):
    l,r=map(int,input().split())
    while nach+x<=l:
        nach+=x
    while nach+1<=r+1:
        nach+=1
        summa+=1
print(summa)

listx=[]

x, y = map(int, input().split(' '))
for i in range(x):
    a, b = map(int, input().split(' '))
    listx.append([a, b])

time = 1
curr = 0
mins = 0
while curr < x:
    while time + y <= listx[curr][0]:
        time += y
    mins += listx[curr][1] - time + 1
    time = listx[curr][1]
    curr += 1
    time += 1
print(mins)

from itertools import *

def main(n,x,l,r):
    s = 0
    curr = 1
    for i in range(n):
        skip = (l[i]-curr) // x
        s += r[i]-curr-skip*x+1
        curr = r[i]+1
    print(s)


def main_input(info=0):
    n,x = list(map(int,input().split()))
    #t = [(int(x)-1,i+1) for i,x in enumerate(input().split())]
    l,r = list(range(n)), list(range(n))
    for i in range(n):
        l[i],r[i] = list(map(int,input().split()))
#    t = [map(int,input().split()) for x in range(n)]
    main(n,x,l,r)

def __starting_point():
    main_input()

__starting_point()

def main():
    rdl = list(map(int,input().split()))
    n, x = rdl
    minutes = 0
    cur = 1
    bests = []
    for i in range(n):
        bests.append(list(map(int,input().split())))
    for i in bests:
        j = 1
        while (cur + x*j) <= i[0]:
            j += 1
        cur += x*(j-1)
        minutes += (i[1]-cur+1)
        cur += (i[1]-cur+1)
    print(minutes)  
    

    
main()


n,x=map(int,input().split())
watch=0
now=1
for i in range(n):
    s,e=map(int,input().split())
    watch+=(s-now)%x+(e-s)+1
    now=e+1
print(watch)

import sys

def main():
    n,x = tuple([int(y) for y in input().split()])
    c = 1
    out = 0
    for i in range(n):
        l,r = tuple([int(y) for y in input().split()])
        s = int((l - c) / x)
        if s > 0:
            c += x * s
        out += r - c + 1
        c = r + 1
    print(out)

def __starting_point():
    main()

__starting_point()

n, x = list(map(int, input().split()))
left = 1
total = 0
for _ in range(n):

    l, r = list(map(int, input().split()))
    total += (l - left) % x + (r - l + 1)
    left = r + 1

print(total)


n,x=input().split()
n,x=int(n),int(x)
lis=[]
for i in range(n):
    lis.append(input().split())
for i in range(n):
    for j in range(2):
        lis[i][j]=int(lis[i][j])
s=0
for i in range(n):
    s+=lis[i][1]-lis[i][0]+1
s+=(lis[0][0]-1)%x
if n>=2:
    for i in range(n-1):
        s+=(lis[i+1][0]-lis[i][1]-1)%x
print(s)


n, x = list(map(int, input().split()))
ans = 0
a = []
t = 0
for i in range(n):
    l, r = list(map(int, input().split()))
    a += [[l, r]]
a.sort()
for elem in a:
    ans += (elem[0] - 1- t) % x + (elem[1] - elem[0]  + 1)
    t = elem[1]# - 1
print(ans)


inp = input()
a = inp.split()
for i in range(0,len(a)):
	a[i] = int(a[i])
time = 0
temp = 0
for i in range(0,a[0]):
    inp2 = input()
    b = inp2.split()    
    b[0] = int(b[0])
    b[1] = int(b[1])
    time += (b[1] - b[0]+1) + (b[0] - temp - 1)%a[1]
    temp = b[1]
    
print(time)


import sys

nums = sys.stdin.readline().split(' ')
n = int(nums[0])
x = int(nums[1])

current = 1
total = 0
for i in range(n):
	next = sys.stdin.readline().split(' ')
	next_l = int(next[0])
	next_r = int(next[1])
	total += next_r-next_l+1+((next_l - current)%x)
	current = (next_r+1)%x

print(total)

import sys
nx=list(map(int,sys.stdin.readline().split()))
n=nx[0]
x=nx[1]
lr=[[0,0]]
for i in range(0,n):
  g=list(map(int,sys.stdin.readline().split()))
  lr=lr+[[g[0],g[1]]]
r=0
gg=0
for j in lr:
  while gg+x<j[0]:
    gg=gg+x
  r=r+j[1]-gg
  gg=j[1]
print(r)