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