N,D = map(int,input().split()) dp = [[0 for _ in range(2)]]*(N+1) t,k = map(int,input().split()) dp[0][0],dp[0][1] = t,k-D for i in range(1,N): T,K = map(int,input().split()) dp[i][0] = dp[i-1][0] + max(T,K-D) dp[i][1] = dp[i-1][1] + max(T-D,K) print(max(dp[-1]))