#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using dd = long double;
namespace {
static bool constexpr dbg = 0;
ll constexpr N = -999;
ll n, k, res;
void init() { cin >> n >> k; }
void solve() {
  res = LONG_LONG_MIN;
  for (ll _ = 1, ii_ = (n); _ <= ii_; ++_) {
    ll f, t;
    cin >> f >> t;
    res = max(res, f - max(t - k, 0ll));
  }
  cout << res;
}
}  // namespace
int main() {
  if (!dbg) {
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  cout << fixed << setprecision(20);
  init();
  solve();
  return 0;
}
