#include <bits/stdc++.h>
int mod = 1e9 + 7;
const int inf = 1e18;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  pair<int, int> a[n + 1];
  for (int i = 1; i < n + 1; i++) cin >> a[i].first >> a[i].second;
  sort(a + 1, a + n + 1);
  int dp[m + 1][n + 1];
  for (int i = 0; i < m + 1; i++)
    for (int j = 0; j < n + 1; j++) dp[i][j] = inf;
  dp[0][0] = 0;
  int mi[m + 1];
  for (int i = 0; i < m + 1; i++) mi[i] = 1e9;
  for (int j = 1; j < n + 1; j++) {
    for (int i = 1; i < m + 1; i++) {
      int t = max(a[j].second, abs(a[j].first - i));
      int s = mi[max(0, a[j].first - t - 1)];
      int tt = m - max(0, a[j].first - t - 1);
      dp[i][j] = min(dp[i][j - 1], min(max(a[j].first - 1, t) - a[j].second,
                                       s - tt + t - a[j].second));
    }
    for (int i = 1; i < m + 1; i++) mi[i] = min(mi[i - 1], dp[i][j] + m - i);
  }
  cout << dp[m][n];
}
