#include <bits/stdc++.h>
using namespace std;
int n, k, a, b, res, r1, r2, r3;
int main() {
  int f = 0;
  while (scanf("%d%d", &n, &k) != EOF) {
    f = 0;
    r1 = 0, r2 = -1000000005;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &a, &b);
      if (b <= k) {
        if (r1 < a) r1 = a;
      } else {
        r3 = (a + k) - b;
        if (r2 < r3) r2 = r3;
      }
    }
    if (r1 > r2 && r1 > 0)
      printf("%d\n", r1);
    else
      printf("%d\n", r2);
  }
  return 0;
}
