n,m = map(int,raw_input().split()) tokyo = [] kyoto = [] for i in range(n): t,k = map(int,raw_input().split()) tokyo.append(t) kyoto.append(k) dp = [[0,0] for i in range(n)] dp[0][0] = tokyo[0] dp[0][1] = kyoto[0] - m for i in range(1,n): dp[i][0] = max(dp[i-1][0] + tokyo[i],dp[i-1][1] + tokyo[i] - m) dp[i][1] = max(dp[i-1][1] + kyoto[i],dp[i-1][0] + kyoto[i] - m) print max(dp[n-1])