using System;
using System.Collections;
using System.Linq;
namespace ARC096
{
    class Program
    {
        static long n;
        static long c;
        static long[] x;
        static long[] v;
        static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            n = long.Parse(s[0]);
            c = long.Parse(s[1]);
            x = new long[n];
            v = new long[n];
            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine().Split(' ');
                x[i] = int.Parse(s[0]);
                v[i] = int.Parse(s[1]);
            }
            long ans = 0;
            long[] total = new long[n];
            for (int i = 0; i < n; i++)
            {
                if (i == 0)
                    total[i] = v[i] - x[i];
                else
                    total[i] = total[i - 1] + v[i] - (x[i] - x[i - 1]);
                ans = Math.Max(ans, total.Max());
            }
            total = new long[n];
            for (int i = 0; i < n; i++)
            {
                if (i == 0)
                    total[i] = v[n - 1 - i] - (c - x[n - 1 - i]);
                else
                    total[i] = total[i - 1] + v[n - 1 - i] - Math.Abs(x[n - 1 - i] - x[n - i]);
                ans = Math.Max(ans, total.Max());
            }
            long[] sv = new long[n];
            sv[0] = v[0];
            for (int i = 1; i < n; i++)
            {
                sv[i] = sv[i - 1] + v[i];
            }
            long vsum = v.Sum();
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++)
                    ans = Math.Max(ans, sv[i] + vsum - sv[j - 1] - (2 * x[i] - x[j] + c));
            for (int j = 0; j < n; j++)
                for (int i = j + 1; i < n; i++)
                    ans = Math.Max(ans, sv[j] + vsum - sv[i - 1] - (2 * (c - x[i]) + x[j]));
            Console.WriteLine(ans);
        }
    }
}