N, D = map(int, input().split()) pos = 0 sum = 0 for i in range(N): t, k = map(int, input().split()) if pos == 0: if k - D > t: pos = 1 sum += k - D else: sum += t if pos == 1: if t - D > k: pos = 0 sum += t - D else: sum += k print(sum)