#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long int, long long int> a,
          pair<long long int, long long int> b) {
  return a.second <= b.second;
}
int32_t main() {
  long long int n, k;
  cin >> n >> k;
  pair<long long int, long long int> p[n];
  for (long long int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
  sort(p, p + n, comp);
  long long int maxm = INT_MIN;
  for (long long int i = 0; i < n; i++) {
    if (k > p[i].second) {
      maxm = max(maxm, p[i].first);
    } else {
      maxm = max(maxm, p[i].first - (p[i].second - k));
    }
  }
  cout << maxm << endl;
  return 0;
}
