using System;

namespace abc095
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            cin = new Scanner();
            int N = cin.nextInt();
            long C = cin.nextLong();
            long[] X = new long[N];
            int[] V = new int[N];
            for (int i = 0; i < N; i++)
            {
                X[i] = cin.nextLong();
                V[i] = cin.nextInt();
            }
            long[] sum = new long[N + 1], sum0 = new long[N + 1], sum2 = new long[N + 1];
            for (int i = 0; i < N; i++)
            {
                sum0[i+1] = sum0[i] + V[i % N];
                sum[i + 1] = sum0[i + 1] - X[i];
                sum2[i + 1] = sum[i + 1] - X[i];
            }
            long[] sumr = new long[N + 1], sumr0 = new long[N + 1], sumr2 = new long[N + 1];
            for (int i = 0; i < N; i++)
            {
                sumr0[i + 1] = sumr0[i] + V[N - i - 1];
                sumr[i + 1] = sumr0[i + 1] - C + X[N - i - 1];
                sumr2[i + 1] = sumr[i + 1] - C + X[N - i - 1];
            }
            long[] max = new long[N + 1], maxr = new long[N + 1], max2 = new long[N + 1], maxr2 = new long[N + 1];
            for (int i = 0; i < N; i++)
            {
                max[i + 1] = Math.Max(max[i], sum[i + 1]);
                maxr[i + 1] = Math.Max(maxr[i], sumr[i + 1]);
                max2[i + 1] = Math.Max(max2[i], sum2[i + 1]);
                maxr2[i + 1] = Math.Max(maxr2[i], sumr2[i + 1]);

            }
            long ans = 0;
            for (int i = 0; i <= N; i++)
            {
                ans = Math.Max(ans, Math.Max(max[i] + maxr2[N - i], maxr[i] + max2[N - i]));
            }
            Console.WriteLine($"{ans}");
        }
        static Scanner cin;
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 26176