using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ARC096D
{
    class Program
    {
        static long N;
        static void Main(string[] args)
        {
            var NC = Console.ReadLine().Split().Select(long.Parse).ToArray();
            N = NC[0];
            long C = NC[1];

            long[] xi = new long[N+1];
            long[] vi = new long[N+1];
            for (long i = 1; i <= N; i++)
            {
                var line = Console.ReadLine().Split().Select(long.Parse).ToArray();
                xi[i] = line[0];
                vi[i] = line[1];
            }

            long[] sumr = Sum(xi, vi);
            long[] suml = Sum(xi.Select(x => C - x).Reverse().ToArray(), vi.Reverse().ToArray());

            long maxr = Math.Max(0, sumr.Max());
            long maxl = Math.Max(0, suml.Max());

            long ans = maxr + maxl;

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static long[] Sum(long[] xi, long[] vi)
        {
            long[] get = new long[N];
            for (long i = 0; i < N; i++)
            {
                get[i] = vi[i + 1] - (xi[i + 1] - xi[i]);
            }

            long[] sum = new long[N + 1];
            for (int i = 0; i < N; i++)
            {
                sum[i + 1] = sum[i] + get[i];
            }

            return sum;
        }
    }
}
