import math N, D = map( int, raw_input().split( ) ) okane = 0 incomes = [] for i in range(N): incomes.append( list(map( int, raw_input().split( ))) ) pos = 0 for i in range(N): if pos == 0: if incomes[i][0] + D < incomes[i][1]: okane += incomes[i][1] - D pos = 1 else: okane += incomes[i][0] elif pos == 1: if incomes[i][1] + D < incomes[i][0]: okane += incomes[i][0] - D pos = 0 else: okane += incomes[i][1] print okane