#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v;
  v.reserve(n);
  int f, t;
  for (int i = 0; i < n; i++) {
    cin >> f >> t;
    v.push_back(make_pair(f, t));
  }
  sort(v.begin(), v.end());
  int i;
  int max = -999999999;
  for (i = n - 1; i >= 0; i--) {
    if (v[i].second <= k) {
      if (max < (v[i].first)) max = v[i].first;
    } else {
      int d = v[i].first - (v[i].second - k);
      if (max < d) max = d;
    }
  }
  cout << max;
}
