using System;
using System.Collections;
using System.Linq;
namespace ARC096
{
    class Program
    {
        static long c = 0;
        static long n;
        static long[] x;
        static long[] v;
        static long max = 0;
        static long min = 0;
        static ArrayList total = new ArrayList();
        static long xc = 0;
        static void Calc(long p)
        {
            if (v[max] - D(xc, x[max]) < v[min] - D(xc, x[min]))
            {
                total.Add(((long)total[total.Count - 1]) + v[min] - D(xc, x[min]));
                xc = x[min];
                if (min == max)
                {
                    long[] total2 = (long[])total.ToArray(typeof(long));
                    Console.WriteLine(total2.Max());
                    Environment.Exit(0);
                }
                min++;
                Calc(xc);
            }
            else if (v[max] - D(xc, x[max]) > v[min] - D(xc, x[min]))
            {
                total.Add(((long)total[total.Count - 1]) + v[max] - D(xc, x[max]));
                xc = x[max];
                if (min == max)
                {
                    long[] total2 = (long[])total.ToArray(typeof(long));
                    Console.WriteLine(total2.Max());
                    Environment.Exit(0);
                }
                min++;
                Calc(xc);
            }
            else
            {
                total.Add(((long)total[total.Count - 1]) + v[max] - D(xc, x[max]));
                if (min == max)
                {
                    long[] total2 = (long[])total.ToArray(typeof(long));
                    Console.WriteLine(total2.Max());
                    Environment.Exit(0);
                }
                xc = x[max];
                long mins = min;
                long maxs = max;
                max--;
                Calc(xc);
                min = mins;
                max = maxs;
                min++;
                xc = x[min];
                Calc(xc);
            }
        }
        static long D(long x1, long x2)
        {
            long dis = Math.Abs(x2 - x1);
            return Math.Min(dis, c - dis);
        }
        static void Main()
        {
            long[] nc = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            n = (long)nc[0];
            max = n - 1;
            c = nc[1];
            x = new long[n];
            v = new long[n];
            for (long i = 0; i < n; i++)
            {
                long[] xv = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
                x[i] = xv[0];
                v[i] = xv[1];
            }
            total.Add((long)0);
            Calc(0);
        }
    }
}