using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var num = int.Parse(input[0]);
        var c = long.Parse(input[1]);
        var xv = Input.arL2D(num);
        var sum = new long[num + 1];
        var dist = new long[num + 1];
        for (var i = 1; i <= num; i++)
            sum[i] = sum[i - 1] + xv[i - 1][1];
        for (var i = 1; i <= num; i++)
        {
            if (sum[i] - xv[i - 1][0] > sum[i - 1])
                dist[i] = xv[i - 1][0];
            else dist[i] = dist[i - 1];
            sum[i] = Max(sum[i] - xv[i - 1][0], sum[i - 1]);
        }
        var sumr = new long[num + 1];
        for (var i = num - 1; i >= 0; i--)
            sumr[i] = sumr[i + 1] + xv[i][1];
        for (var i = num - 1; i >= 0; i--)
            sumr[i] -= c - xv[i][0];
        var res = sum[num];
        for (var j = num - 1; j >= 0; j--)
        {
            res = Max(res, sumr[j]);
            res = Max(res, sum[j]);
            res = Max(res, sum[j] + sumr[j] - Min(c - xv[j][0], dist[j]));
        }
        WriteLine(res);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}
