using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int N;
        private long C;
        private long[] X;
        private int[] V;

        private long[] sum;

        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            C = sc.NextLong();
            X = new long[N];
            V = new int[N];
            for (int i = 0; i < N; i++)
            {
                X[i] = sc.NextLong();
                V[i] = sc.NextInt();
            }
        }

        public void Solve()
        {
            Scan();

            long ans = 0;
            for (int i = 0; i < N; i++)
            {
                ans = Math.Max(Q(i), ans);
               
            }
            Console.WriteLine(ans);
        }



        private long Q(int n)
        {
            long res = 0;
            res -= Math.Min(X[n], C - X[n]);
            res += V[n];
            //Console.WriteLine($"{n} {res}");
            res = Math.Max(0, res);
            long migi = res;
            long hidari = res;
            int migin = n;
            int hidarin = n;
            for (int i = 1; i < N; i++)
            {
                int miginext = migin + 1;
                long migidist;
                if (miginext == N)
                {
                    migidist = C - X[N - 1] + X[0];
                    migin = 0;
                }
                else
                {
                    migidist = X[miginext] - X[migin];
                    migin = miginext;
                }

                migi += V[migin];
                migi -= migidist;
                //Console.WriteLine(migi);
                res = Math.Max(res, migi);


                int hidarinext = hidarin - 1;
                long hidaridist;
                if (hidarinext == -1)
                {
                    hidaridist = C - X[N - 1] + X[0];
                    hidarin = N - 1;
                }
                else
                {
                    hidaridist = X[hidarin] - X[hidarinext];
                    hidarin = hidarinext;
                }

                hidari += V[hidarin];
                hidari -= hidaridist;
                res = Math.Max(res, hidari);
            }

            return res;
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}