using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair<T> { public T x, y; public Pair(T xx, T yy) { x = xx; y = yy; } }
    private static int[] dx = { 1, 0, -1, 0 };
    private static int[] dy = { 0, -1, 0, 1 };
    public static void Main()
    {
        int N = NextInt();
        long C = NextLong();
        long[] x = new long[N];
        long[] v = new long[N];
        for (int i = 0; i < N; i++) { x[i] = NextLong(); v[i] = NextLong(); }

        //iまで逆から参照した時の最大値
        long[,] mx = new long[2, N + 1];

        long score = 0;
        long max_score = 0;
        long ret_score = 0;
        long walk = 0;
        for (int i = N - 1; i >= 0; i--)
        {
            score += v[i];
            walk = C - x[i];
            if (score - walk > max_score)
            {
                max_score = score - walk;
                ret_score = score - 2 * walk;
            }
            mx[0, i] = max_score;
            mx[1, i] = ret_score;
        }

        score = max_score = ret_score = walk = 0;
        for (int i = 0; i < N; i++)
        {
            score += v[i];
            walk = x[i];
            ret_score = Math.Max(score - 2 * walk + mx[0, i + 1], mx[1, i + 1] + score - walk);
            max_score = Math.Max(Math.Max(score - walk, ret_score), max_score);
        }
        Console.WriteLine(Math.Max(max_score, mx[0, 0]));
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}
