using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

        int susiCount = (int)inpt[0];
        TotalLength = inpt[1];
        this.SusiList = new Susi[susiCount];

        long totalCal = 0;
        List<int> flags = new List<int>();
        for (int i = 0; i < susiCount; i++) {
            SusiList[i] = new Susi(Reader.ReadLine());
            totalCal += SusiList[i].Calorie;
            flags.Add(i);
        }
        SusiList = SusiList.OrderBy(a => a.Position).ToArray();
        this.TotalCalorie = totalCal;
        max = Math.Max(max, totalCal - Math.Max(TotalLength - SusiList[0].Position, SusiList.Last().Position));

        List<int> subFlags = new List<int>(flags);
        subFlags.RemoveAt(0);
        long ans = Math.Max(max, GetAns(0, subFlags) + SusiList[0].Calorie - SusiList[0].Position);
        subFlags = new List<int>(flags);
        subFlags.RemoveAt(subFlags.Count - 1);
        ans = Math.Max(ans, GetAns(SusiList.Length - 1, subFlags) + SusiList.Last().Calorie - (TotalLength - SusiList.Last().Position));
        Console.WriteLine(ans);
    }

    private Dictionary<long, Dictionary<string, long>> dic = new Dictionary<long, Dictionary<string, long>>();
    private long GetAns(int pos, List<int> flags) {
        string key = string.Join("#", flags);
        if(!dic.ContainsKey(pos)) {
            dic.Add(pos, new Dictionary<string, long>());
        }
        if(dic[pos].ContainsKey(key)) {
            return dic[pos][key];
        }

        long ans = 0;
        if(flags.Count > 0) {
            List<int> subFlags = new List<int>(flags);
            int nextPos = 0;
            long nextMove = 0;
            if(pos > flags.Last()) {
                nextPos = flags.First();
                subFlags.RemoveAt(0);
                nextMove = SusiList[nextPos].Position + TotalLength - SusiList[pos].Position;
            } else {
                nextPos = flags.Where(a => pos <= a).First();
                subFlags.Remove(nextPos);
                nextMove = SusiList[nextPos].Position - SusiList[pos].Position;
            }
            ans = Math.Max(ans, GetAns(nextPos, subFlags) - nextMove + SusiList[nextPos].Calorie);
            subFlags = new List<int>(flags);
            if(SusiList[pos].Position < SusiList[flags.First()].Position) {
                nextPos = flags.Last();
                subFlags.RemoveAt(subFlags.Count - 1);
                nextMove = SusiList[pos].Position + TotalLength - SusiList[nextPos].Position;
            } else {
                nextPos = flags.Where(a => pos >= a).Last();
                subFlags.Remove(nextPos);
                nextMove = SusiList[pos].Position - SusiList[nextPos].Position;
            }
            ans = Math.Max(ans, GetAns(nextPos, subFlags) - nextMove + SusiList[nextPos].Calorie);
        }
        dic[pos][key] = ans;
        return ans;
    }

    private long max = 0;

    private Susi[] SusiList;
    private long TotalCalorie;

    private class Susi {
        public long Position;
        public long Calorie;
        public Susi(string init) {
            long[] tmp = init.Split(' ').Select(a => long.Parse(a)).ToArray();
            this.Position = tmp[0];
            this.Calorie = tmp[1];
        }
    }

    private long TotalLength;


    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"

15 10000000000
400000000 1000000000
800000000 1000000000
1900000000 1000000000
2400000000 1000000000
2900000000 1000000000
3300000000 1000000000
3700000000 1000000000
3800000000 1000000000
4000000000 1000000000
4100000000 1000000000
5200000000 1000000000
6600000000 1000000000
8000000000 1000000000
9300000000 1000000000
9700000000 1000000000

";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}
