#include <bits/stdc++.h>
using namespace std;
int main() {
  int x[10001];
  int n, k, t, max = -1000000000;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> t;
    if (t > k) {
      x[i] = x[i] - t + k;
    }
    if (x[i] > max) {
      max = x[i];
    }
  }
  cout << max << endl;
  return 0;
}
