#include #include using namespace std; typedef long long LL; const int N = 110; int n, d, a[N][2]; LL f[N][2]; int main() { // freopen("work.in", "r", stdin); // freopen("work.out", "w", stdout); scanf("%d%d", &n, &d); for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i][0], &a[i][1]); memset(f, 0xcf, sizeof(f)); f[0][0] = 0LL; for (int i = 1; i <= n; ++i) { for (int j = 0; j < 2; ++j) { f[i][j] = max(f[i - 1][j] + a[i][j], f[i - 1][1 - j] + a[i][j] - d); } } printf("%lld\n", max(f[n][0], f[n][1])); return 0; }