#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools from queue import PriorityQueue import bisect import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """2 10000 # 20000 32000 # 24000 23000 # """ # sys.stdin = io.StringIO(_INPUT) def main(): N, D = map(int, input().split()) T = [None for _ in range(N)] K = [None for _ in range(N)] for i in range(N): T[i], K[i] = map(int, input().split()) dp = [[0, 0] for _ in range(N)] dp[0][0] = T[0] dp[0][1] = K[0] - D for i in range(1, N): dp[i][0] = max(dp[i-1][0] + T[i], dp[i-1][1] + T[i] - D) dp[i][1] = max(dp[i-1][0] + K[i] - D, dp[i-1][1] + K[i]) print(max(dp[N-1])) if __name__ == '__main__': main()