#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, k, x, y, n, i;
  cin >> n >> k;
  vector<int> v;
  for (i = 1; i <= n; i++) {
    cin >> a >> b;
    if (b > k) {
      x = b - k;
      y = a - x;
      v.push_back(y);
    } else {
      v.push_back(a);
    }
  }
  sort(v.begin(), v.end());
  vector<int>::iterator it;
  it = v.end() - 1;
  cout << *it << endl;
  return 0;
}
