#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T b, T p, T m) {
  T ret;
  if (p == 0) return 1;
  if (p & 1) {
    ret = (bigmod(b, p / 2, m) % m);
    return ((b % m) * ret * ret) % m;
  } else {
    ret = (bigmod(b, p / 2, m) % m);
    return (ret * ret) % m;
  }
}
template <class T>
inline T _sqrt(T a) {
  return (T)sqrt((double)a);
}
template <class T, class X>
inline T _pow(T a, X b) {
  T res = 1;
  for (int i = 1; i <= b; i++) res *= a;
  return res;
}
int dx4[] = {1, -1, 0, 0};
int dy4[] = {0, 0, 1, -1};
int dx6[] = {0, 0, 1, -1, 0, 0};
int dy6[] = {1, -1, 0, 0, 0, 0};
int dz6[] = {0, 0, 0, 0, 1, -1};
int dx8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dy8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dkx8[] = {-1, 1, -1, 1, -2, -2, 2, 2};
int dky8[] = {2, 2, -2, -2, 1, -1, 1, -1};
int tc = 1;
const long long int mx = 100000;
int main() {
  long long i, k, a, b, n, ans;
  while (cin >> n >> k) {
    vector<pair<long long, long long> > vp;
    for (i = 0; i < n; i++) {
      scanf("%lld %lld", &a, &b);
      vp.push_back(pair<long long, long long>(a, b));
    }
    sort(vp.begin(), vp.end(), greater<pair<long long, long long> >());
    ans = INT_MIN;
    for (i = 0; i < n; i++) {
      if (vp[i].second <= k)
        ans = max(ans, vp[i].first);
      else
        ans = max(ans, vp[i].first - (vp[i].second - k));
    }
    cout << ans << "\n";
  }
  return 0;
}
