import sequtils,strutils,math var N, D : int T, K : int dp : array[110, array[2, int]] (N, D) = stdin.readline.split.map(parseInt) dp[0][1] = -D for n in 1..N: (T, K) = stdin.readline.split.map(parseInt) dp[n][0] = max(dp[n - 1][0] + T, dp[n - 1][1] + T - D) dp[n][1] = max(dp[n - 1][1] + K, dp[n - 1][0] + K - D) echo max(dp[N])