#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int N_MAX = 100'000;
long table[N_MAX + 2][4] = {};

int main() {
    int N;
    long C;
    cin >> N >> C;
    for (int n = 0; n < N; n++) {
        int x;
        long v;
        cin >> x >> v;
        table[n + 1][0] = x;
        table[n + 1][1] = v;
    }

    for (int n = 0; n < N; n++) {
        table[n + 1][2] = table[n][2] + table[n + 1][1];
    }

    for (int n = N - 1; n >= 0; n--) {
        table[n + 1][3] = table[n + 2][3] + table[n + 1][1];
    }

    int max = 0;

    for (int r = 0; r < N; r++) {
        int rv = table[r + 1][2];
        long rc = table[r + 1][0];
        if (rv - rc > max) max = rv - rc;

        for (int l = N - 1; l > r; l--) {
            int lv = table[l + 1][3];
            long lc = C - table[l + 1][0];
            if (rv - 2 * rc + lv - lc > max) max = rv - 2 * rc + lv - lc;
        }
    }

    for (int l = N - 1; l >= 0; l--) {
        int lv = table[l + 1][3];
        long lc = C - table[l + 1][0];
        if (lv - lc > max) max = lv - lc;

        for (int r = 0; r < l; r++) {
            int rv = table[r + 1][2];
            long rc = table[r + 1][0];
            if (lv - 2 * lc + rv - rc > max) max = lv - 2 * lc + rv - rc;
        }
    }

    cout << max << endl;

    return 0;
}
