#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct sushi
{
  unsigned long long x, v;
}

int main()
{
  unsigned long long n, c;
  cin >> n >> c;
  
  vector<sushi> s(n);
  
  for(int i = 0; i < n; i++)
  {
    sushi tmp;
    cin >> tmp.x >> tmp.v;
    s.push_back(tmp);
  }
  
  sort(s.begin(), s.end(), [](sushi& a, sushi& b)->bool{return a.x<b.x;})
  unsigned long long l_nut=0, r_nut=0, lpos=0, rpos=c;
  int i;
  for(i = 0; i < n; i++)
  {
    if(s[i].x > c/2)
    {
      break;
    }
    l_nut -= s[i].x - lpos;
    l_nut += s[i].v;
    lpos = s[i].x;
  }
  
  for(int j = n - 1; j >= i; j--)
  {
    r_nut -= rpos - s[j].x;
    r_nut += s[j].v;
    rpos = s[j].x;
  }
  
  maxnut = l_nut - (r_pos - l_pos) + r_nut - (c-s[n-1].x);
  maxnut = maxnut < (l_nut + r_nut - lpos) ? l_nut + r_nut - lpos : maxnut;
  maxnut = maxnut < l_nut ? l_nut : maxnut;
  maxnut = maxnut < r_nut ? r_nut : maxnut;
  
    
  cout << maxnut << endl;
}