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

namespace arc096_b
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long[,] susi = new long[x[0] + 1, 2];
            for (int i = 1; i <= x[0]; i++)
            {
                long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
                susi[i, 0] = a[0]; susi[i, 1] = a[1];
            }
            susi[0, 0] = x[1];
            long ret = 0; long sum = 0;
            for (int i = 0; i <= x[0]; i++)
            {
                sum += susi[i, 1];
                long now = sum;
                for (int j = 0; j <= x[0] - i; j++)
                {
                    now += susi[(x[0] - j + 1) % (x[0] + 1), 1];
                    var a = new long[] { susi[i, 0], x[1] - susi[(x[0] - j + 1) % (x[0] + 1), 0] };
                    ret = Math.Max(ret, now - a.Min() * 2 - a.Max());
                }
            }
            Console.WriteLine(ret);
        }
    }
}