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[] scoreR = new long[n+1];//時計回りで何個取るか
    long[] totalScoreR = new long[n+1];//取ったときの得点から歩数引く
    long[] totalScoreTurnR = new long[n+1];//取ったときの得点から歩数の2倍引く
    long[] scoreL = new long[n+1];//時計回りで何個取るか
    long[] totalScoreL = new long[n+1];//取ったときの得点から歩数引く
    long[] totalScoreTurnL = new long[n+1];
    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];
    }

    for(long eatNum = 0; eatNum < n; eatNum++)
    {
      scoreMemo += vertexes[eatNum,1];
      scoreR[eatNum+1] = scoreMemo;
      totalScoreR[eatNum+1] = scoreR[eatNum+1] - vertexes[eatNum,0];
      totalScoreTurnR[eatNum+1] = scoreR[eatNum+1] - 2*vertexes[eatNum,0];
    }

    for(long eatNum = 0; eatNum < n; eatNum++)
    {
      scoreMemo += vertexes[eatNum,1];
      scoreR[eatNum+1] = scoreMemo;
      totalScoreR[eatNum+1] = scoreR[eatNum+1] - vertexes[eatNum,0];
      totalScoreTurnR[eatNum+1] = scoreR[eatNum+1] - 2*vertexes[eatNum,0];
    }

    for(long eatNum = 0; eatNum < n; eatNum++)
    {
      scoreMemo += vertexes[n-1-eatNum,1];
      scoreR[eatNum+1] = scoreMemo;
      totalScoreR[eatNum+1] = scoreR[eatNum+1] - (n-vertexes[n-1-eatNum,0]);
      totalScoreTurnR[eatNum+1] = scoreR[eatNum+1] - 2*(n-vertexes[n-1-eatNum,0]);
    }

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