#include <bits/stdc++.h>
using namespace std;
int n, k, x, y, maxim;
int main() {
  cin >> n >> k;
  int maxim = -1e9;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    if (y > k && x + k - y > maxim) maxim = x + k - y;
    if (y <= k && x > maxim) maxim = x;
  }
  cout << maxim;
  return 0;
}
