using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long n = long.Parse(input[0]);
		long c = long.Parse(input[1]);
    long[,] vertexes = new long[n,2];//ここに受け取る
    long scoreMemo = 0;
    long answer = 0;
    for(long i = 0; i < n; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);//１行ごとに受け取る
      vertexes[i,0] = nums[0];
      vertexes[i,1] = nums[1];
    }

    long eatPointR = 0;
    long eatPointL = 0;

    for(long eatNum = 0; eatNum <= n; eatNum++)
    {
    if(eatNum > 0) eatPointR += vertexes[i-1,1];
      for(long eatNumL = 0; eatNumL <= n-eatNum; eatNumL++)
      {
      if(eatNumL > 0) eatPointL += vertexes[n-i,1];
        answer = Math.Max(answer, eatPointL+eatPointR
          -vertexes[i-1,0]-(n-vertexes[n-i,0])-Math.Min(vertexes[i-1,0], n-vertexes[n-i,0]));
      }
    }

		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}