#include <bits/stdc++.h>
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int dx_ar[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy_ar[] = {1, 0, -1, 1, -1, 1, 0, -1};
template <typename type>
void print_vector(type d1_arr);
template <typename type>
void print_2dvector(type d2_arr);
std::vector<std::vector<int>> padding(std::vector<std::vector<int>> arr,
                                      int pad);
template <typename type>
void print_map(type map);
inline std::vector<long long> str_int_split(char *s);
inline std::vector<std::vector<long long>> in_d2_arr(int N, int size = 1000);
inline std::vector<long long> in_d1_arr(int size = 1000);
inline double d2_distance(int x1, int y1, int x2, int y2);
inline int d2_manhattan(int x1, int y1, int x2, int y2);
int main() {
  auto v1 = in_d1_arr();
  long long N = v1[0];
  long long C = v1[1];
  printf("\n%lld\n", C);
  auto v2 = in_d2_arr(N);
  std::map<long long, long long> map;
  std::set<long long> plus;
  std::set<long long> minus;
  long long cal = 0;
  for (auto m : v2) {
    map[m[0]] = m[1];
    plus.insert(m[0]);
    minus.insert(m[0] - C);
  }
  long long state = 0;
  while (true) {
    std::set<long long>::iterator itr1 = plus.begin();
    std::set<long long>::iterator itr2 = minus.end();
    --itr2;
    bool key = false;
    while (itr1 != plus.end()) {
      if (map[*itr1] - abs(*itr1 - state) < 0) {
        ++itr1;
        continue;
      } else {
        key = true;
        break;
      }
    }
    while (itr2 != minus.begin()) {
      if (map[C + *itr2] - abs(*itr2 - state) < 0) {
        --itr2;
        continue;
      } else {
        key = true;
        break;
      }
    }
    if (!key) {
      break;
    }
    auto c1 = map[*itr1] - abs(*itr1 - state);
    auto c2 = map[C + *itr2] - abs(*itr2 - state);
    auto dis1 = abs(*itr1 - state);
    auto dis2 = abs(*itr2 - state);
    if (c1 > 0 && c2 > 0) {
      if (C + *itr2 == *itr1) {
        cal += std::max(c1, c2);
        break;
      } else {
        if (dis1 < dis2) {
          state = *itr1;
          cal += c1;
        } else {
          state = C + *itr2;
          cal += c2;
          minus.erase(*itr2);
        }
      }
    } else if (c1 > 0) {
      state = *itr1;
      cal += c1;
      plus.erase(*itr1);
    } else if (c2 > 0) {
      state = C + *itr2;
      cal += c2;
      minus.erase(*itr2);
    } else {
      break;
    }
  }
  printf("%lld\n", cal);
}
template <typename type>
void print_vector(type d1_arr) {
  for (auto seg : d1_arr) {
    std::cout << seg;
    std::cout << " ";
  }
  std::cout << std::endl;
}
template <typename type>
void print_2dvector(type d2_arr) {
  for (auto seg1 : d2_arr) {
    for (auto seg2 : seg1) {
      std::cout << seg2;
      std::cout << " ";
    }
    std::cout << std::endl;
  }
}
template <typename type>
void print_map(type map) {
  for (auto m : map) {
    std::cout << m.first;
    std::cout << ":";
    std::cout << m.second;
    std::cout << " ";
  }
  std::cout << std::endl;
}
std::vector<std::vector<int>> padding(std::vector<std::vector<int>> arr,
                                      int pad) {
  std::vector<std::vector<int>> arr_c = arr;
  int height = arr_c.size();
  int width = arr_c[0].size();
  std::vector<int> v;
  v.resize(width);
  fill(v.begin(), v.end(), pad);
  arr_c.insert(arr_c.begin(), v);
  arr_c.push_back(v);
  int i;
  for ((i) = 0; (i) < (height + 2); ++(i)) {
    arr_c[i].insert(arr_c[i].begin(), pad);
    arr_c[i].resize(width + 2);
  }
  arr_c.shrink_to_fit();
  return arr_c;
}
inline std::vector<long long> str_int_split(char *s) {
  char *tok = strtok(s, " ,");
  std::vector<long long> v;
  while (tok != NULL) {
    v.push_back(atoll(tok));
    tok = strtok(NULL, " ,");
  }
  return v;
}
inline std::vector<std::vector<long long>> in_d2_arr(int N, int size) {
  int i;
  std::vector<std::vector<long long>> v;
  for ((i) = 0; (i) < (N); ++(i)) {
    char *lines;
    lines = new char[size];
    scanf(" %[a-zA-Z (+-0-9_) #.]/n", (lines));
    ;
    v.push_back(str_int_split(lines));
    delete[] lines;
  }
  return v;
}
inline std::vector<long long> in_d1_arr(int size) {
  std::vector<long long> v;
  char *lines;
  lines = new char[size];
  scanf(" %[a-zA-Z (+-0-9_) #.]/n", (lines));
  ;
  v = str_int_split(lines);
  delete[] lines;
  return v;
}
inline double d2_distance(int x1, int y1, int x2, int y2) {
  return sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
}
inline int d2_manhattan(int x1, int y1, int x2, int y2) {
  return (abs(x2 - x1) + abs(y2 - y1));
}
