#include <bits/stdc++.h>
using namespace std;
int n, k, ma, ans;
int f[10010], t[10010];
int main() {
  while (scanf("%d%d", &n, &k) != EOF) {
    scanf("%d%d", &f[0], &t[0]);
    if (t[0] >= k)
      ma = f[0] - t[0] + k;
    else
      ma = f[0];
    for (int i = 1; i < n; i++) {
      scanf("%d%d", &f[i], &t[i]);
      if (t[i] >= k)
        ans = f[i] - t[i] + k;
      else
        ans = f[i];
      if (ans > ma) ma = ans;
    }
    printf("%d\n", ma);
  }
  return 0;
}
