#include using namespace std; //#define int long long #define FOR(i, j, k) for(int i = j; i < k; ++i) #define rep(i, j) FOR(i, 0, j) #define INF (1 << 30) typedef unsigned long long ull; typedef pair P; typedef pair Pi; const int MOD = 1e9 + 7; const int dy[] = {0, 0, 1, -1}; const int dx[] = {1, -1, 0, 0}; template void chmin(T& a, const T& b) { a = min(a, b); } template void chmax(T& a, const T& b) { a = max(a, b); } int n, d, ans = 0; int t[100], k[100]; int dp[101][2]; signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> d; rep(i, n) cin >> t[i] >> k[i]; dp[0][0] = dp[0][1] = 0; dp[1][0] = t[0]; dp[1][1] = k[0] - d; FOR(i, 1, n) { dp[i + 1][0] = max(dp[i][0] + t[i], dp[i][1] + t[i] - d); dp[i + 1][1] = max(dp[i][0] + k[i] - d, dp[i][1] + k[i]); } cout << max(dp[n][0], dp[n][1]) << endl; return 0; }