#include <bits/stdc++.h>
using namespace std;
int n, k, x, m, s;
vector<int> f, t, f1;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> x >> m;
    f.push_back(x);
    t.push_back(m);
  }
  for (int i = 0; i < n; i++) {
    if (t[i] < k) {
      f1.push_back(f[i]);
    } else {
      s = f[i] - (t[i] - k);
      f1.push_back(s);
    }
  }
  sort(f1.begin(), f1.end());
  cout << f1.back();
}
