#include <bits/stdc++.h>
int main() {
  long long n, k, f[10005], t[10005], i, j, s = -1000000005, g = -1000000005, r;
  scanf("%lld %lld", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%lld %lld", &f[i], &t[i]);
  }
  for (j = 0; j < n; j++) {
    if (t[j] > k) {
      r = f[j] - (t[j] - k);
      if (r > s) s = r;
    } else if (t[j] <= k) {
      if (f[j] > g) g = f[j];
    }
  }
  if (g > s)
    printf("%lld", g);
  else if (s >= g)
    printf("%lld", s);
  return 0;
}
