#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0, f, t;
  cin >> f >> t;
  if (t > k)
    t = t - k;
  else
    t = 0;
  ans = f - t;
  n--;
  while (n--) {
    cin >> f >> t;
    if (t > k)
      t = t - k;
    else
      t = 0;
    ans = max(ans, f - t);
  }
  cout << ans;
}
