Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.

The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers f_{i} and t_{i}. Value t_{i} shows the time the Rabbits need to lunch in the i-th restaurant. If time t_{i} exceeds the time k that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal f_{i} - (t_{i} - k). Otherwise, the Rabbits get exactly f_{i} units of joy.

Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value. 


-----Input-----

The first line contains two space-separated integers — n (1 ≤ n ≤ 10^4) and k (1 ≤ k ≤ 10^9) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — f_{i} (1 ≤ f_{i} ≤ 10^9) and t_{i} (1 ≤ t_{i} ≤ 10^9) — the characteristics of the i-th restaurant.


-----Output-----

In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. 


-----Examples-----
Input
2 5
3 3
4 5

Output
4

Input
4 6
5 8
3 6
2 3
2 2

Output
3

Input
1 5
1 7

Output
-1

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
from math import inf

def main():
	try:
		(n, k) = invr()
		joy = -inf
		for _ in range(n):
			(f, t) = invr()
			if t > k:
				joy = max(f - t + k, joy)
			else:
				joy = max(f, joy)
		print(joy)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = map(int, input().split())
ma = float('-inf')
for _ in range(n):
	(a, b) = map(int, input().split())
	if b > k:
		x = a - b + k
	else:
		x = a
	if x > ma:
		ma = x
print(ma)


(n, k) = [int(i) for i in input().split()]
m = []
for _ in range(n):
	(f, t) = [int(i) for i in input().split()]
	if t <= k:
		m.append(f)
	else:
		m.append(f - (t - k))
print(max(m))


(n, k) = map(int, input().strip().split())
l = list()
for i in range(0, n):
	(f, t) = map(int, input().strip().split())
	if t > k:
		l.append(f - t + k)
	else:
		l.append(f)
l.sort(reverse=True)
print(l[0])


(n, k) = map(int, input().strip().split())
(arr, joy) = ([], [])
for i in range(n):
	restaurant = list(map(int, input().strip().split()))
	arr.append(restaurant)
for i in arr:
	if i[1] > k:
		joy.append(i[0] - (i[1] - k))
	else:
		joy.append(i[0])
print(max(joy))


(n, k) = map(int, input().split())
cafes = [tuple(map(int, input().split())) for _ in range(n)]
print(max([c[0] - (c[1] - k) if c[1] > k else c[0] for c in cafes]))


(n, a) = map(int, input().split())
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	if y > a:
		c = x - (y - a)
	else:
		c = x
	b.append(c)
print(max(b))


(n, k) = list(map(int, input().split()))
gj = -1000000000000000000
for i in range(n):
	(f, t) = list(map(int, input().split()))
	j = f - t + k if t > k else f
	if j > gj:
		gj = j
print(gj)


(n, k) = map(int, input().split())
rest = []
JOY = []
for i in range(n):
	rest.append(list(map(int, input().split())))
for i in rest:
	if i[1] > k:
		JOY.append(i[0] - (i[1] - k))
	else:
		JOY.append(i[0])
print(max(JOY))


(n, k) = map(int, input().split())
maxK = -10 ** 10
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		maxK = max(maxK, f - (t - k))
	else:
		maxK = max(maxK, f)
print(maxK)


(n, t) = map(int, input().split())
an = None
for i in range(n):
	(f, ti) = map(int, input().split())
	if ti > t:
		x = f - ti + t
	else:
		x = f
	if not an:
		an = x
	else:
		an = max(an, x)
print(an)


class lunchrush:
	from sys import stdin, stdout
	(n, k) = map(int, stdin.readline().rstrip().split())
	(f1, t1) = map(int, stdin.readline().rstrip().split())
	ret = 0
	if t1 <= k:
		ret = f1
	else:
		ret = f1 - (t1 - k)
	for x in range(1, n):
		tempret = 0
		(f, t) = map(int, stdin.readline().rstrip().split())
		if t <= k:
			tempret = f
		else:
			tempret = f - (t - k)
		if tempret > ret:
			ret = tempret
	stdout.write(str(ret) + '\n')


(n, k) = map(int, input().split())
a = []
r = 0
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		a.append(f - (t - k))
	else:
		a.append(f)
print(max(a))


(n, k) = map(int, input().split())
f = t = 0
(f, t) = map(int, input().split())
if t > k:
	fun = f - t + k
else:
	fun = f
for i in range(n - 1):
	(f, t) = map(int, input().split())
	if t > k:
		if f - t + k > fun:
			fun = f - t + k
	elif f > fun:
		fun = f
print(fun)


nk = input().split()
n = int(nk[0])
k = int(nk[1])
joy = []
for i in range(n):
	ft = input().split()
	f = int(ft[0])
	t = int(ft[1])
	if t > k:
		j = f - (t - k)
	else:
		j = f
	joy.append(j)
mx = joy[0]
for i in range(1, n):
	if joy[i] > mx:
		mx = joy[i]
print(mx)


import math

def get_primes(prime_supr):
	is_prime = [0] * 2 + [1] * prime_supr
	for i in range(2, int(math.sqrt(prime_supr)) + 1):
		if is_prime[i]:
			for j in range(i * i, prime_supr + 1, i):
				is_prime[j] = 0
	return is_prime

def get_int():
	return map(int, input().split())
(n, k) = get_int()
a = []
for i in range(n):
	(x, y) = get_int()
	if y > k:
		a.append(x - (y - k))
	else:
		a.append(x)
print(max(a))


import sys
(n_rest, time) = tuple((int(x) for x in sys.stdin.readline().split()))
max_joy = -100000000000000000000
for i in range(n_rest):
	(f, t) = tuple((int(x) for x in sys.stdin.readline().split()))
	cur_joy = 0
	if t > time:
		cur_joy = f - (t - time)
	else:
		cur_joy = f
	max_joy = max(max_joy, cur_joy)
print(max_joy)


(n, c) = map(int, input().split())
(a, b) = map(int, input().split())
if b > c:
	ss = a - (b - c)
else:
	ss = a
for i in range(1, n):
	(a, b) = map(int, input().split())
	if b > c:
		s = a - (b - c)
	else:
		s = a
	if s > ss:
		ss = s
print(ss)


solve = []
(n, k) = map(int, input().split())
for _ in range(n):
	(x, y) = map(int, input().split())
	solve.append(x if k > y else x - (y - k))
print(max(solve))


st = input().split()
n = int(st[0])
k = int(st[1])
joy = -10 ** 9
for i in range(n):
	st = input().split()
	f = int(st[0])
	t = int(st[1])
	if t > k:
		joy = max(joy, f - (t - k))
	else:
		joy = max(joy, f)
print(joy)


(n, k) = [int(i) for i in input().split()]
s1 = -1000000001
for _ in range(n):
	(f, t) = [int(i) for i in input().split()]
	if t <= k:
		s1 = max(s1, f)
	else:
		temp = f - (t - k)
		s1 = max(s1, temp)
print(s1)


s = input()
n = int(s[:s.find(' ')])
k = int(s[s.find(' '):])
maxJ = None
for i in range(n):
	s = input()
	f = int(s[:s.find(' ')])
	t = int(s[s.find(' '):])
	joy = 0
	if t > k:
		joy = f - (t - k)
	else:
		joy = f
	if maxJ == None:
		maxJ = joy
	elif joy > maxJ:
		maxJ = joy
print(maxJ)


(n, k) = map(int, input().split())
m1 = -999999999
c1 = -999999999
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		c1 = f - (t - k)
	else:
		c1 = f
	m1 = max(c1, m1)
print(m1)


(n, k) = map(int, input().split())
print(max([x[0] - max(0, x[1] - k) for x in [list(map(int, input().split())) for i in range(n)]]))


(n, k) = map(int, input().split())
m = -10 ** 9
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		p = f - t + k
	else:
		p = f
	m = max(m, p)
print(m)


(n, k) = [int(x) for x in input().split()]
ans = -(1e+18 + 5)
for i in range(n):
	(f, t) = [int(x) for x in input().split()]
	if t <= k:
		ans = max(ans, f)
	else:
		ans = max(ans, f - (t - k))
print(ans)


nk = list(map(int, input().split()))
ft = []
for k in range(nk[0]):
	ft.append(list(map(int, input().split())))
maximum = -10 ** 9
for i in range(nk[0]):
	if ft[i][1] <= nk[1]:
		maximum = max(maximum, ft[i][0])
	else:
		maximum = max(maximum, ft[i][0] - (ft[i][1] - nk[1]))
print(maximum)


(n, k) = map(int, input().split())
l = []
for _ in range(n):
	(f, t) = map(int, input().split())
	if t <= k:
		l.append(f)
	else:
		l.append(f - (t - k))
print(max(l))


(n, k) = list(map(int, input().split()))
a = -1 << 30
for i in range(n):
	(f, t) = list(map(int, input().split()))
	if t > k:
		f -= t - k
	a = max(a, f)
print(a)


(n_val, k_val) = list(map(int, input().split()))
joy_list = list()
for idx in range(n_val):
	(f_val, t_val) = list(map(int, input().split()))
	if t_val > k_val:
		joy = f_val - (t_val - k_val)
	else:
		joy = f_val
	joy_list.append(joy)
print(max(joy_list))


(a, b) = map(int, input().split())
v = []
while a > 0:
	(c, d) = map(int, input().split())
	if d < b:
		v.append(c)
	else:
		v.append(c - (d - b))
	a -= 1
print(max(v))


def inp():
	return map(int, input().split())
m = -(10 ** 9 + 1)
(n, k) = inp()
for i in range(n):
	(f, t) = inp()
	if t > k:
		m = max(f - (t - k), m)
	else:
		m = max(f, m)
print(m)


data = input().split()
(N, K) = (int(data[0]), int(data[1]))
resturants = [None] * N
for i in range(N):
	tmp_in = input().split()
	resturants[i] = list(map(int, tmp_in))
joy_li = []
for i in range(N):
	current_rest = resturants[i]
	if current_rest[1] <= K:
		joy_li.append(current_rest[0])
		continue
	else:
		joy_li.append(current_rest[0] - (current_rest[1] - K))
		continue
print(max(joy_li))


(n, k) = list(map(int, input().split()))
l = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	if b <= k:
		l += [a]
	else:
		l += [a - (b - k)]
else:
	print(max(l))


a = list(map(int, input().split()))
n = int(a[0])
k = int(a[1])
max = -1000000000
j = 0
m = [0] * n
for i in range(n):
	m = list(map(int, input().split()))
	f = int(m[0])
	t = int(m[1])
	if t > k:
		j = f - (t - k)
		if j > max:
			max = j
	else:
		j = f
		if j > max:
			max = j
print(max)


vals = list()
(n, k) = map(int, input().split(' '))
joy = -99999999999999
for i in range(n):
	(f, t) = map(int, input().split(' '))
	vals.append([f, t])
for j in range(n):
	if vals[j][1] >= k:
		if vals[j][0] - (vals[j][1] - k) >= joy:
			joy = vals[j][0] - (vals[j][1] - k)
	elif vals[j][0] >= joy:
		joy = vals[j][0]
print(joy)


(n, k) = map(int, input().split())
f = []
t = []
joy = []
for i in range(n):
	(a, b) = map(int, input().split())
	f.append(a)
	t.append(b)
for i in range(n):
	if t[i] > k:
		joy.append(f[i] - (t[i] - k))
	else:
		joy.append(f[i])
print(max(joy))


def answer(n, k, f_ary, t_ary):
	max_joy = -10 ** 10
	for i in range(n):
		if k >= t_ary[i]:
			joy = f_ary[i]
		else:
			joy = f_ary[i] - (t_ary[i] - k)
		if joy > max_joy:
			max_joy = joy
	return max_joy

def main():
	(n, k) = [int(i) for i in input().split()]
	f_ary = [0] * n
	t_ary = [0] * n
	for j in range(n):
		(f_ary[j], t_ary[j]) = [int(i) for i in input().split()]
	print(answer(n, k, f_ary, t_ary))
main()


(*a,) = map(int, input().split())
(n, k, mx) = (a[0], a[1], -10 ** 10)
for _ in range(n):
	(*x,) = map(int, input().split())
	if x[1] > k:
		mx = max(mx, x[0] - (x[1] - k))
	else:
		mx = max(mx, x[0])
print(mx)


max_val = 10 ** 9 * 4
max_val = -max_val
(N, K) = map(int, input().split())
for n in range(N):
	(F, T) = map(int, input().split())
	max_val = max(max_val, F - max(0, T - K))
print(max_val)


(n, k) = map(int, input().split())
answer = None
for i in range(n):
	(f, t) = map(int, input().split())
	answeri = f - max(t - k, 0)
	if i == 0 or answer < answeri:
		answer = answeri
print(answer)


import math
(n, k) = map(int, input().split(' '))
result = list()
for i in range(n):
	(f, t) = map(int, input().split(' '))
	if t > k:
		temp = f - (t - k)
		result.append(temp)
	else:
		result.append(f)
print(max(result))


(n, k) = map(int, input().split())
f = [0] * n
t = [0] * n
for i in range(n):
	(f[i], t[i]) = map(int, input().split())
for i in range(n):
	if t[i] > k:
		f[i] = f[i] - (t[i] - k)
x = f[0]
for i in range(n):
	if f[i] > x:
		x = f[i]
print(x)


import math
a = input().split(' ')
n = int(a[0])
k = int(a[1])
m = -math.inf
for i in range(n):
	a = input().split(' ')
	a[0] = int(a[0])
	a[1] = int(a[1])
	if a[1] > k:
		a[0] = a[0] - (a[1] - k)
	if a[0] > m:
		m = a[0]
print(m)


from sys import stdin

def main():
	(n, k) = map(int, stdin.readline().strip().split())
	m = -9999999999
	for _ in range(n):
		(f, t) = map(int, stdin.readline().strip().split())
		m = max(m, f - max(t - k, 0))
	return m
print(main())


X = list(map(int, input().split()))
MAX = -10 ** 9
for i in range(X[0]):
	Y = list(map(int, input().split()))
	MAX = max(MAX, min(Y[0], Y[0] - (Y[1] - X[1])))
print(MAX)


(n, k) = map(int, input().split())
m_j = -10000000000.0
for _ in range(n):
	(f, t) = map(int, input().split())
	m_j = max(f - max(0, t - k), m_j)
print(m_j)


def solve(k, vals):
	maximum = float('-inf')
	curr = -1
	for i in range(0, len(vals)):
		if vals[i][1] > k:
			curr = vals[i][0] - (vals[i][1] - k)
		else:
			curr = vals[i][0]
		maximum = max(curr, maximum)
	return maximum
(n, k) = map(int, input().split(' '))
vals = list()
_n = 0
while _n < n:
	(f, t) = map(int, input().split(' '))
	vals.append([f, t])
	_n += 1
print(solve(k, vals))


from sys import stdin, stdout
import math
(n, k) = [int(x) for x in stdin.readline().strip().split()]
joy = []
time = []
for line in stdin.readlines():
	line = line.strip().split()
	joy.append(int(line[0]))
	time.append(int(line[1]))
results = []
for i in range(n):
	if time[i] > k:
		result = joy[i] - time[i] + k
		results.append(result)
	else:
		results.append(joy[i])
value = max(results)
print(value)


(n, k) = map(int, input().split())
lst = []
for i in range(n):
	(f, t) = map(int, input().split())
	if t <= k:
		lst.append(f)
	else:
		lst.append(f - (t - k))
print(max(lst))


def big_fun(arr, k):
	di = {}
	for (f, t) in arr:
		if f in di:
			di[f].append(t)
		else:
			di[f] = [t]
	ans = float('-inf')
	for i in di:
		if len(di[i]) == 1:
			if di[i][0] > k:
				tmp = i - (di[i][0] - k)
			else:
				tmp = i
			ans = max(ans, tmp)
		else:
			for j in di[i]:
				if j > k:
					tmp = i - (j - k)
				else:
					tmp = i
				ans = max(ans, tmp)
	return ans
(n, k) = list(map(int, input().rstrip().split()))
arr = []
for i in range(n):
	x = list(map(int, input().rstrip().split()))
	arr.append(x)
print(big_fun(arr, k))


x = input().split(' ')
all = []
for i in range(int(x[0])):
	all.append(input().split(' '))
joy = float('-inf')
for y in all:
	if int(y[1]) > int(x[1]):
		temp = int(y[0]) - (int(y[1]) - int(x[1]))
	else:
		temp = int(y[0])
	if temp > joy:
		joy = temp
print(joy)


(n, k) = [int(x) for x in input().split(' ')]
max_joy = -float('inf')
for r in range(n):
	(f, t) = [int(x) for x in input().split(' ')]
	max_joy = max(max_joy, min(f, f - t + k))
print(max_joy)


(n, k) = map(int, input().split())
(f, t) = map(int, input().split())
mx = f + min(k - t, 0)
for i in range(n - 1):
	(f, t) = map(int, input().split())
	mx = max(f + min(k - t, 0), mx)
print(mx)


(n, k) = list(map(int, input().split()))
max_fun = -2 ** 31
for i in range(n):
	(fun, time) = list(map(int, input().split()))
	total_fun = 0
	if time > k:
		total_fun += fun - (time - k)
	else:
		total_fun += fun
	if total_fun > max_fun:
		max_fun = total_fun
print(max_fun)


(n, m) = map(int, input().split())
x = -10 ** 9
for i in range(n):
	(a, b) = map(int, input().split())
	if b < m:
		x = max(x, a)
	else:
		x = max(x, a - (b - m))
print(x)


(n, k) = map(int, input().split())
maxf = -float('inf')
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		maxf = max(maxf, f - (t - k))
	else:
		maxf = max(maxf, f)
print(maxf)


(n, k) = map(int, input().split())
l = []
for i in range(n):
	(f, t) = map(int, input().split())
	l.append((f, t))
l2 = []
for i in l:
	if i[1] <= k:
		l2.append(i[0])
	else:
		l2.append(i[0] - (i[1] - k))
print(max(l2))


(r, k) = [int(x) for x in input().split()]
maxJoy = None
for i in range(r):
	(f, t) = [int(x) for x in input().split()]
	if t > k:
		j = f - (t - k)
	else:
		j = f
	if maxJoy == None or j > maxJoy:
		maxJoy = j
print(maxJoy)


(n, k) = input().split()
n = int(n)
k = int(k)
Mx = -1000000000.0
for i in range(1, n + 1):
	(f, t) = input().split()
	f = int(f)
	t = int(t)
	if t > k:
		nx = f - (t - k)
	else:
		nx = f
	if nx > Mx:
		Mx = nx
print(Mx)


(n, k) = [int(i) for i in input().split()]
t = n * [0]
f = n * [0]
(f[0], t[0]) = [int(i) for i in input().split()]
if t[0] > k:
	d = f[0] - t[0] + k
else:
	d = f[0]
for i in range(1, n):
	(f[i], t[i]) = [int(i) for i in input().split()]
	tedad = 0
	if t[i] <= k:
		tedad = f[i]
	else:
		tedad = f[i] - t[i] + k
	if tedad > d:
		d = tedad
print(d)


(n, k) = map(int, input().split())
res = -10 ** 9
for i in range(n):
	(f, t) = map(int, input().split())
	res = max(res, min(f, f - (t - k)))
print(res)


l = lambda : map(int, input().split())
(n, k) = l()
print(max(((lambda f, t: f - max(0, t - k))(*l()) for _ in [0] * n)))


(n, k) = map(int, input().split())
l = []
while n:
	(x, y) = map(int, input().split())
	if y >= k:
		ans = x - (y - k)
		l.append(ans)
	else:
		l.append(x)
	n = n - 1
print(max(l))


(n, k) = map(int, input().split())
f = []
t = []
a = -10000000000
for i in range(n):
	(F, T) = map(int, input().split())
	f.append(F)
	t.append(T)
for i in range(n):
	if t[i] > k:
		x = f[i] - (t[i] - k)
	else:
		x = f[i]
	a = max(a, x)
print(a)


st = [int(i) for i in input().split(' ')]
n = st[0]
k = st[1]
pleas = []
for i in range(n):
	a = [int(j) for j in input().split(' ')]
	f = a[0]
	t = a[1]
	if t > k:
		pleas.append(f - (t - k))
	else:
		pleas.append(f)
print(max(pleas))


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007
(n, k) = In()
mx = -P
for i in range(n):
	(f, t) = In()
	if t <= k:
		mx = max(mx, f)
	else:
		mx = max(mx, f - (t - k))
print(mx)


(n, k) = map(int, input().split())
res = -10000000000
for _ in range(n):
	(n, m) = map(int, input().split())
	if m > k:
		n -= m - k
	res = max(res, n)
print(res)


(n, k) = map(int, input().split())
mx = -1000000000000
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		mx = max(mx, f - t + k)
	else:
		mx = max(mx, f)
print(mx)


(n, k) = map(int, input().split())
count = 0
ar = []
for _ in range(n):
	(a, b) = map(int, input().split())
	if b > k:
		count = a - (b - k)
	else:
		count = a
	ar.append(count)
print(max(ar))


(n, k) = map(int, input().split(' '))
m = -1000000000000
for j in range(n):
	(f, t) = map(int, input().split(' '))
	v = 0
	if t > k:
		v = f - (t - k)
	else:
		v = f
	if v > m:
		m = v
print(m)


(n, k) = map(int, input().split(' '))
ans = -1000000001
for i in range(n):
	(a, b) = map(int, input().split(' '))
	if b > k:
		ans = max([ans, a - b + k])
	else:
		ans = max([ans, a])
print(ans)


(n, k) = map(int, input().split())
c = []
for i in range(n):
	(fi, ti) = map(int, input().split())
	if ti > k:
		c.append(fi - (ti - k))
	else:
		c.append(fi)
print(max(c))


[n, k] = list(map(int, input().split(' ')))
r = -10 ** 10
for i in range(n):
	[f, t] = list(map(int, input().split(' ')))
	r = max(r, min(f, f - (t - k)))
print(r)


(n, k) = map(int, input().split())
Max = -float('inf')
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		y = f - (t - k)
		if y > Max:
			Max = y
	else:
		y = f
		if y > Max:
			Max = y
print(Max)


(k, T) = map(int, input().split())
a = []
for x in range(k):
	(f, t) = map(int, input().split())
	if t <= T:
		a.append(f)
	else:
		a.append(f - (t - T))
print(max(a))


p = [int(n) for n in input().split()]
s = []
for n in range(p[0]):
	s.append([int(n) for n in input().split()])
k = p[1]
op = []
for n in range(p[0]):
	if s[n][1] > k:
		op.append(s[n][0] - s[n][1] + k)
	else:
		op.append(s[n][0])
print(max(op))


a = []
a = input().split()
n = int(a[0])
k = int(a[1])
x = []
for i in range(0, n):
	x.append([int(j) for j in input().split()])
joy = []
for i in range(0, n, 1):
	if x[i][1] > k:
		j = x[i][0] - (x[i][1] - k)
		joy.append(j)
	else:
		j = x[i][0]
		joy.append(j)
print(max(joy))


(n, k) = map(int, input().split())
ans = -10000000000000
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		ans = max(ans, f - (t - k))
	else:
		ans = max(ans, f)
print(ans)


(n, k) = map(int, input().split())
s = [0] * n
for i in range(n):
	(f, t) = map(int, input().split())
	if t <= k:
		s[i] += f
	elif t > k:
		s[i] += f - (t - k)
print(max(s))


(n, k) = map(int, input().split())
s = -1 << 30
for i in range(n):
	(x, y) = map(int, input().split())
	if y > k:
		x -= y - k
	s = max(s, x)
print(s)


X = list(map(int, input().split()))
MAX = -1000000000
for i in range(X[0]):
	Y = list(map(int, input().split()))
	MAX = max(MAX, Y[0] if Y[1] <= X[1] else Y[0] - (Y[1] - X[1]))
print(MAX)


temp = input()
temp = temp.split()
n = int(temp[0])
k = int(temp[1])
my_list = []
for x in range(n):
	temp = input()
	temp = temp.split()
	temp = [int(x) for x in temp]
	my_list.append(temp)
if my_list[0][1] - k <= 0:
	max_fun = my_list[0][0]
else:
	max_fun = my_list[0][0] - (my_list[0][1] - k)
for (x, y) in my_list:
	if k - y >= 0:
		if x > max_fun:
			max_fun = x
	elif x - (y - k) > max_fun:
		max_fun = x - (y - k)
print(max_fun)


(n, k) = map(int, input().split())
res = -10000000000
for i in range(n):
	(f, t) = map(int, input().split())
	res = max(res, f + min(0, k - t))
print(res)


import sys
import math
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(input())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def main():
	(n, k) = get_ints_in_variables()
	mx = -1000000007
	for _ in range(0, n):
		(fi, ti) = get_ints_in_variables()
		if ti <= k:
			mx = max(fi, mx)
		elif ti > k:
			tmp = fi - (ti - k)
			mx = max(mx, tmp)
	print(mx)
main()


def lunch_rush(k, f, t):
	if t > k:
		joy = f - (t - k)
		return joy
	else:
		return f
(n, k) = list(map(int, input().split()))
l = []
for i in range(n):
	(f, t) = list(map(int, input().split()))
	result = lunch_rush(k, f, t)
	l.append(result)
print(max(l))


(x, y) = [int(x) for x in input('').split()]
fun = []
for i in range(x):
	(p, q) = [int(x) for x in input('').split()]
	if q > y:
		fun.append(p - (q - y))
	else:
		fun.append(p)
print(max(fun))


import math
arr = input().split()
n = int(arr[0])
k = int(arr[1])
max = -1 * math.inf
for i in range(n):
	arr = input().split()
	f = int(arr[0])
	t = int(arr[1])
	val = f
	if t > k:
		val = val - (t - k)
	if val > max:
		max = val
print(int(max))


import sys
(n, k) = [int(x) for x in sys.stdin.readline().strip().split()]
ans = -999999999999999999999999999999999999999999
for i in range(0, n):
	(f, t) = [int(x) for x in sys.stdin.readline().strip().split()]
	ans = max(ans, f - max(0, t - k))
print(ans)


(n, k) = map(int, input().split())
max_ = -10000000000
for i in range(n):
	(f, t) = map(int, input().split())
	if t <= k:
		if max_ < f:
			max_ = f
	elif t > k:
		if max_ < f - (t - k):
			max_ = f - (t - k)
print(max_)


(restaurants, time) = map(int, input().split())
ans = []
for tc in range(restaurants):
	(joy, time_spent) = map(int, input().split())
	if time_spent <= time:
		ans.append(joy)
	else:
		ans.append(joy - (time_spent - time))
print(max(ans))


import math
(n, k) = map(int, input().split())
t = []
f = []
m = -math.inf
for i in range(n):
	(x, y) = map(int, input().split())
	f.append(x)
	t.append(y)
for i in range(n):
	if t[i] > k:
		m = max(m, f[i] - t[i] + k)
	else:
		m = max(m, f[i])
print(m)


(n, k) = list(map(int, input().split()))
ma = -1000000000
for _ in range(n):
	(f, t) = list(map(int, input().split()))
	if t > k:
		va = f + k - t
		if va > ma:
			ma = va
	else:
		va = f
		if va > ma:
			ma = va
print(ma)


n = [int(x) for x in input().split()]
t = n[1]
j = []
for i in range(n[0]):
	x = [int(x) for x in input().split()]
	if x[1] > t:
		j.append(x[0] - (x[1] - t))
	else:
		j.append(x[0])
print(max(j))


(I, r) = (lambda : map(int, input().split()), -10 ** 9)
(n, k) = I()
exec('f,t=I();q=min(f,f+k-t);r=max(r,q);' * n)
print(r)


(n, k) = list(map(int, input().split()))
j = 0
maxj = -1000000000
for i in range(n):
	(f, t) = list(map(int, input().split()))
	if t > k:
		j += f - t + k
	else:
		j += f
	maxj = max(j, maxj)
	j = 0
print(maxj)


n = list(map(int, input().split()))
lst = []
for i in range(n[0]):
	n1 = list(map(int, input().split()))
	if n1[1] <= n[1]:
		lst.append(n1[0])
	else:
		lst.append(n1[0] - (n1[1] - n[1]))
print(max(lst))


s1 = input()
n = int(s1.split()[0])
k = int(s1.split()[1])
t = []
for i in range(0, n):
	s2 = input()
	f = int(s2.split()[0])
	v = int(s2.split()[1])
	if v - k > 0:
		t.append(f - (v - k))
	else:
		t.append(f)
print(max(t))


(n, k) = map(int, input().split())
ls = []
for _ in range(n):
	t = tuple(map(int, input().split()))
	ls.append(t)
arr = []
for i in range(n):
	if ls[i][1] > k:
		x = ls[i][0] - (ls[i][1] - k)
		arr.append(x)
	else:
		arr.append(ls[i][0])
print(max(arr))


(n, k) = input().split()
n = int(n)
k = int(k)
maxjoy = -10000000000
for i in range(n):
	(fi, ti) = input().split()
	fi = int(fi)
	ti = int(ti)
	if ti <= k and maxjoy < fi:
		maxjoy = fi
	elif ti > k and maxjoy < fi - (ti - k):
		maxjoy = fi - (ti - k)
print(maxjoy)


import sys
(n, k) = map(int, input().split())
arr = []
for _ in range(n):
	(fi, ti) = map(int, input().split())
	arr.append((fi, ti))
(arr, ans) = (sorted(arr), -sys.maxsize)
for item in arr:
	if item[1] <= k:
		ans = max(ans, item[0])
	else:
		ans = max(ans, item[0] - (item[1] - k))
print(ans)


(n, k) = input().split()
(n, k) = (int(n), int(k))
f = []
t = []
for i in range(n):
	(tmp1, tmp2) = input().split()
	(tmp1, tmp2) = (int(tmp1), int(tmp2))
	f.append(tmp1)
	t.append(tmp2)
res = -9999999999999999
for i in range(n):
	if t[i] >= k:
		tmp = f[i] - (t[i] - k)
	else:
		tmp = f[i]
	res = max(res, tmp)
print(res)


import sys
input = sys.stdin.buffer.readline
(n, k) = map(int, input().split())
joy = -1000000000
while n:
	n -= 1
	(f, t) = map(int, input().split())
	if t <= k:
		temp_joy = f
	else:
		temp_joy = f - t + k
	if joy < temp_joy:
		joy = temp_joy
print(joy)


(n, k) = map(int, input().split())
list1 = []
for i in range(n):
	list1.append(list(map(int, input().split())))
k1 = 0
for i in list1:
	if i[1] > k:
		joy = i[0] - (i[1] - k)
	else:
		joy = i[0]
	if k1 == 0:
		max = joy
	elif joy > max:
		max = joy
	k1 += 1
print(max)


(n, k) = map(int, input().split())
s = set()
for i in range(n):
	(a, b) = map(int, input().split())
	if b > k:
		s.add(a - (b - k))
	else:
		s.add(a)
print(max(s))


(n, k) = map(int, input().split())
ans = -99999999999999
for _ in range(n):
	(f, t) = map(int, input().split())
	ans = max(ans, f - max(0, t - k))
print(ans)


(n, k) = map(int, input().split())
M = -1000000000
for _ in ' ' * n:
	(f, t) = map(int, input().split())
	M = max(M, f - (t - k)) if t >= k else max(M, f)
print(M)


(n, t) = map(int, input().split())
m = -10000000000
while n:
	n -= 1
	(a, b) = map(int, input().split())
	x = a
	if b > t:
		x = a - b + t
	if x > m:
		m = x
print(m)


(n, k) = map(int, input().split())
ans = -1000000001
for _ in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		ans = max(ans, f - (t - k))
	else:
		ans = max(ans, f)
print(ans)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

def ip():
	return int(sys.stdin.readline())

def sip():
	return sys.stdin.readline()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
(n, k) = mip()
val = -10000000000
while n:
	n -= 1
	(a, b) = mip()
	if b > k:
		count = a - (b - k)
	else:
		count = a
	val = max(val, count)
print(val)


(n, k) = map(int, input().split())
ans = -1 * 10 ** 18
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		ans = max(ans, f - (t - k))
	else:
		ans = max(ans, f)
print(ans)


(n, k) = list(map(int, input().split()))
p = []
for i in range(0, n):
	(f, t) = list(map(int, input().split()))
	if t > k:
		p.append(f - (t - k))
	else:
		p.append(f)
print(max(p))


(n, k) = map(int, input().split())
ans = -1000000000
for i in range(n):
	(a, b) = map(int, input().split())
	ans = max(ans, a - max(0, b - k))
print(ans)


l = list(map(int, input().split()))
f = list(map(int, input().split()))
if f[1] > l[1]:
	m = f[0] - (f[1] - l[1])
else:
	m = f[0]
for i in range(1, l[0]):
	f = list(map(int, input().split()))
	if f[1] > l[1]:
		m = max(m, f[0] - (f[1] - l[1]))
	else:
		m = max(m, f[0])
print(m)


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
val_i = get_ints()
mej = -1e+18
for x in range(val_i[0]):
	rest = get_ints()
	if rest[1] > val_i[1]:
		mej = max(mej, rest[0] - (rest[1] - val_i[1]))
	else:
		mej = max(mej, rest[0])
print(mej)


import sys, os.path
if os.path.exists('in_py.txt'):
	sys.stdin = open('in_py.txt', 'r')
	sys.stdout = open('out_py.txt', 'w')

def get_ints():
	return map(int, sys.stdin.readline().strip().split())
(n, k) = get_ints()
mx = -1000000000.0
while n > 0:
	n = n - 1
	(f, t) = get_ints()
	if t > k:
		mx = max(mx, f - (t - k))
	else:
		mx = max(mx, f)
print(mx)


(n, k) = map(int, input().split())
maxi = -1 * 10 ** 10
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		j = f - (t - k)
	else:
		j = f
	maxi = max(maxi, j)
print(maxi)


a = [int(x) for x in input().split()]
n = a[0]
k = a[1]
l1 = []
while n:
	s = [int(x) for x in input().split()]
	f = s[0]
	t = s[1]
	if t > k:
		l1.append(f - (t - k))
	else:
		l1.append(f)
	n -= 1
print(max(l1))


(a, b) = map(int, input().split())
(c, d) = ([], -10 ** 10 - 1)
for i in range(a):
	c.append(list(map(int, input().split())))
for i in c:
	if i[1] <= b:
		d = max(d, i[0])
	else:
		d = max(d, b - i[1] + i[0])
print(d)


a = list(map(int, input().split()))
(n, k, b) = (a[0], a[1], [])
for i in range(n):
	c = list(map(int, input().split()))
	b.append(c)
if b[0][1] >= k:
	max_t = b[0][0] - b[0][1] + k
else:
	max_t = b[0][0]
for i in range(n):
	if k < b[i][1]:
		if max_t < b[i][0] - b[i][1] + k:
			max_t = b[i][0] - b[i][1] + k
	elif max_t < b[i][0]:
		max_t = b[i][0]
print(max_t)


I = lambda : map(int, input().split())
(n, k) = I()
print(max(((lambda a, b: a - max(0, b - k))(*I()) for i in [0] * n)))


firstLine = [int(x) for x in input().split()]
reps = firstLine[0]
time = firstLine[1]
best = -9999999999999999
for i in range(0, reps):
	d = [int(x) for x in input().split()]
	temp = d[0] - max(d[1] - time, 0)
	if temp > best:
		best = temp
print(best)


lst1 = []
lst2 = []
z = list(map(int, input().split()))
for i in range(z[0]):
	c = list(map(int, input().split()))
	if c[1] <= z[1]:
		lst1.append(c[0])
	else:
		t = c[0] - (c[1] - z[1])
		lst2.append(t)
if len(lst1) == 0:
	print(max(lst2))
elif len(lst2) == 0:
	print(max(lst1))
else:
	print(['%d' % max(lst2), '%d' % max(lst1)][max(lst1) >= max(lst2)])


(a, b) = map(int, input().split())
v = []
for i in range(a):
	(n, m) = map(int, input().split())
	if m - b > 0:
		v.append(n - (m - b))
	else:
		v.append(n)
print(max(v))


(n, k) = map(int, input().split())
(f, t) = map(int, input().split())
j = f - (t - k) if t > k else f
a = j
for i in range(n - 1):
	(f, t) = map(int, input().split())
	j = f - (t - k) if t > k else f
	if j > a:
		a = j
print(a)


(n, k) = list(map(int, input().split()))
max_joy = -100000000000000000
for _ in range(n):
	(f_i, t_i) = list(map(int, input().split()))
	if t_i > k:
		max_joy = max(max_joy, f_i - (t_i - k))
	else:
		max_joy = max(max_joy, f_i)
print(max_joy)


(n, m) = map(int, input().split())
r = -float('inf')
for i in range(n):
	(f, t) = map(int, input().split())
	r = max(r, f if t <= m else f - (t - m))
print(r)


(n, k) = map(int, input().split())
max = -1000000000
for i in range(n):
	(f, t) = map(int, input().split())
	if t <= k:
		s = f
	else:
		s = f - (t - k)
	if s > max:
		max = s
print(max)


import sys
(n, k) = [int(x) for x in sys.stdin.readline().split()]
(ff, ft) = [int(x) for x in sys.stdin.readline().split()]
h = 0
if ft > k:
	h = ff - (ft - k)
else:
	h = ff
for i in range(n - 1):
	hh = 0
	(f, t) = [int(x) for x in sys.stdin.readline().split()]
	if t > k:
		hh = f - (t - k)
	else:
		hh = f
	if hh > h:
		h = hh
print(h)


from math import inf

def solve(n, k, ft):
	maxi = -inf
	for (f, t) in ft:
		v = f - (t - k) if t > k else f
		maxi = max(maxi, v)
	return maxi

def main():
	(n, k) = list(map(int, input().split()))
	ft = [tuple(map(int, input().split())) for _ in range(n)]
	print(solve(n, k, ft))
main()


(n, t) = map(int, input().split())
curr = float('-inf')
for i in range(n):
	(joy, time) = map(int, input().split())
	if time <= t:
		curr = max(curr, joy)
	else:
		curr = max(curr, joy - (time - t))
print(curr)


ar = []
for i in input().split(' '):
	ar.append(int(i))
ch = 0
curr = 0
for i in range(ar[0]):
	temp = []
	for j in input().split(' '):
		temp.append(int(j))
	val = 0
	if ch != 0:
		if temp[1] > ar[1]:
			val = temp[0] - (temp[1] - ar[1])
		else:
			val = temp[0]
		if val > curr:
			curr = val
	else:
		if temp[1] > ar[1]:
			val = temp[0] - (temp[1] - ar[1])
		else:
			val = temp[0]
		curr = val
		ch = 1
print(curr)


s = input('')
(n, k) = s.split(' ')
n = int(n)
k = int(k)
l = []
for i in range(n):
	s = input('')
	l1 = s.split(' ')
	l1 = list(map(int, l1))
	l.append(l1)
l2 = []
for i in range(n):
	if l[i][1] > k:
		temp = l[i][0] - (l[i][1] - k)
		l2.append(temp)
	elif l[i][1] == k:
		temp = l[i][0]
		l2.append(temp)
	else:
		temp = l[i][0]
		l2.append(temp)
print(max(l2))


from sys import stdin, stdout

def solve():
	ans = int(-1000000000.0)
	(n, k) = map(int, stdin.readline().split())
	for i in range(n):
		(f, t) = map(int, stdin.readline().split())
		if t > k:
			ans = max(ans, f - (t - k))
		else:
			ans = max(ans, f)
	print(ans)
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
t = 1
while t <= tcs:
	solve()
	t += 1


(n, k) = map(int, input().split())
curr = -9999999999999999999999999999999999
for i in range(n):
	(f, t) = map(int, input().split())
	if t >= k:
		f = f - (t - k)
	if f > curr:
		curr = f
print(curr)


(n, k) = [int(x) for x in input().split()]
x = []
for i in range(n):
	(f, t) = [int(x) for x in input().split()]
	if t > k:
		x.append(f - (t - k))
	else:
		x.append(f)
print(max(x))


def main():
	(n, k) = [int(i) for i in input().split()]
	result = -float('inf')
	for i in range(n):
		(f, t) = [int(i) for i in input().split()]
		result = max(result, f - max(0, t - k))
	print(result)
main()


(n, k) = [int(i) for i in input().split()]
m = None
for i in range(n):
	(fi, ti) = [int(i) for i in input().split()]
	if ti > k:
		fi = fi - (ti - k)
	if m is None:
		m = fi
	else:
		m = max(fi, m)
print(m)


(n, k) = [int(x) for x in input().split(' ')]
ans = -99999999999999

def func(f, t):
	if t <= k:
		return f
	return f - (t - k)
for _ in range(n):
	(f, t) = [int(x) for x in input().split(' ')]
	ans = max(ans, func(f, t))
print(ans)


def getMax(li):
	max_val = li[0]
	for i in range(1, len(li)):
		if abs(li[i]) > abs(max_val):
			max_val = li[i]
			continue
	return max_val
data = input().split()
(N, K) = (int(data[0]), int(data[1]))
resturants = [None] * N
for i in range(N):
	tmp_in = input().split()
	resturants[i] = list(map(int, tmp_in))
joy_li = []
for i in range(N):
	current_rest = resturants[i]
	if current_rest[1] <= K:
		joy_li.append(current_rest[0])
		continue
	else:
		joy_li.append(current_rest[0] - (current_rest[1] - K))
		continue
print(max(joy_li))


(n, k) = map(int, input().split())
counter = -10 ** 9
for i in range(n):
	(a, b) = map(int, input().split())
	counter = max(counter, a - max(b - k, 0))
print(counter)


(n, k) = list(map(int, input().split()))
f = [list(map(int, input().split())) for i in range(n)]
print(sorted((v[0] if v[1] <= k else v[0] - (v[1] - k) for v in f))[-1])


(n, k) = input().split()
f_arr = []
t_arr = []
for a in range(0, int(n)):
	(f, t) = input().split()
	f_arr.append(int(f))
	t_arr.append(int(t))
joy_arr = []
for l in range(0, int(n)):
	if t_arr[l] > int(k):
		joy_arr.append(f_arr[l] - (t_arr[l] - int(k)))
	if t_arr[l] <= int(k):
		joy_arr.append(f_arr[l])
print(max(joy_arr))


l = lambda : map(int, input().split())
(n, k) = l()
f = []
for _ in ' ' * n:
	(f1, t1) = l()
	if t1 <= k:
		f.append(f1)
	else:
		f.append(f1 - (t1 - k))
print(max(f))


val_i = list(map(int, input().split(' ')))
mej = -1e+18
for x in range(val_i[0]):
	rest = list(map(int, input().split(' ')))
	if rest[1] > val_i[1]:
		mej = max(mej, rest[0] - (rest[1] - val_i[1]))
	else:
		mej = max(mej, rest[0])
print(mej)


def main():
	(n, k) = map(int, input().split())
	joy = []
	for _ in range(n):
		(fi, ti) = map(int, input().split())
		joy.append(fi - ti + k if ti > k else fi)
	print(max(joy))
main()


s = [int(i) for i in input().split()]
d = []
for i in range(s[0]):
	a = [int(i) for i in input().split()]
	pos = 0
	if a[1] > s[1]:
		pos = a[0] - (a[1] - s[1])
	else:
		pos = a[0]
	d.append(pos)
print(max(d))


(n, k) = list(map(int, input().split()))
t = []
for j in range(n):
	(a, p) = list(map(int, input().split()))
	if p > k:
		t.append([a - (p - k), a])
	else:
		t.append([a, k])
t.sort()
print(t[-1][0])


(n, k) = map(int, input().split())
f = [0] * n
t = [0] * n
maxjoy = -2 * 10 ** 10
for i in range(n):
	(f[i], t[i]) = map(int, input().split())
for i in range(n):
	if t[i] <= k:
		if f[i] > maxjoy:
			maxjoy = f[i]
	elif f[i] - (t[i] - k) > maxjoy:
		maxjoy = f[i] - (t[i] - k)
print(maxjoy)


(n, k) = tuple(map(int, input().split()))
ft = [tuple(map(int, input().split())) for _ in range(n)]
print(max([f - t + k if t > k else f for (f, t) in ft]))


(n, k) = map(int, input().split())
joy = float('-inf')
for _ in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		fun = f - (t - k)
		joy = max(joy, fun)
	else:
		joy = max(joy, f)
print(joy)


(n, k) = [int(i) for i in input().split()]
max_joy = -10000000000
for i in range(n):
	(f, t) = [int(c) for c in input().split()]
	if t > k:
		joy = f - (t - k)
	else:
		joy = f
	if joy > max_joy:
		max_joy = joy
print(max_joy)


(n, k) = map(int, input().split())
max_joy = -float('inf')
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		f = f - t + k
	if max_joy < f:
		max_joy = f
print(max_joy)


from sys import stdin
a = []
(n, k) = list(map(int, stdin.readline().split()))
for _ in range(int(n)):
	(f, t) = list(map(int, stdin.readline().split()))
	if t > k:
		a.append(f - (t - k))
	else:
		a.append(f)
print(sorted(a)[-1])


import sys
(n, k) = map(int, sys.stdin.readline().split())
ans = -1000000000
for i in range(n):
	(f, t) = map(int, sys.stdin.readline().split())
	if t > k:
		joy = f - (t - k)
	else:
		joy = f
	if ans < joy:
		ans = joy
print(ans)


import math

def ost(a, b):
	if a % b != 0:
		return 1
	return 0
(n, k) = map(int, input().split())
ans = 0
for i in range(n):
	(f, t) = map(int, input().split())
	tmp = 0
	if t > k:
		tmp = f - (t - k)
	else:
		tmp = f
	if i > 0:
		ans = max(tmp, ans)
	else:
		ans = tmp
print(ans)


sa = input().split(' ')
rs = int(sa[0])
k = int(sa[1])
joy = -99999999999999999999999999999999999
for x in range(rs):
	sa2 = input().split(' ')
	f_i = int(sa2[0])
	t_i = int(sa2[1])
	if t_i > k:
		joy = max(joy, f_i - (t_i - k))
	else:
		joy = max(joy, f_i)
print(joy)


(n, j) = map(int, input().split())
c = []
for i in range(n):
	a = list(map(int, input().split()))
	if a[1] <= j:
		c.append(a[0])
	else:
		c.append(a[0] - (a[1] - j))
print(max(c))


line = input()
line = line.split()
n = int(line[0])
k = int(line[1])
line = input()
line = line.split()
f = int(line[0])
t = int(line[1])
if t > k:
	pjoy = f - (t - k)
else:
	pjoy = f
if n > 1:
	for i in range(1, n):
		line = input()
		line = line.split()
		f = int(line[0])
		t = int(line[1])
		if t > k:
			joy = f - (t - k)
		else:
			joy = f
		if joy > pjoy:
			pjoy = joy
print(pjoy)


(n, k) = map(int, input().split())
m = -10000000000
for i in range(n):
	(f, t) = map(int, input().split())
	if k >= t:
		m = max(m, f)
	else:
		m = max(m, f - (t - k))
print(m)


(x, y) = input().split()
(a, b) = (int(x), int(y))
(list, list1, list2) = ([], [], [])
for i in range(a):
	(l, m) = input().split()
	(c, d) = (int(l), int(m))
	list.append((c, d))
for i in range(a):
	if list[i][1] <= b:
		list1.append(list[i][0])
	else:
		list1.append(list[i][0] - list[i][1] + b)
print(max(list1))


(n, m) = map(int, input().strip().split()[:2])
k = []
for x in range(n):
	(x, y) = map(int, input().strip().split()[:2])
	if y <= m:
		k.append(x)
	else:
		k.append(m + x - y)
print(max(k))


(a, b) = input().split()
a = int(a)
b = int(b)
maxi = -1000000000
for i in range(a):
	(c, d) = input().split()
	c = int(c)
	d = int(d)
	if b < d:
		sumi = c - (d - b)
	else:
		sumi = c
	maxi = max(maxi, sumi)
print(maxi)


import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l
mod = int(1000000000.0) + 7

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def linp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(a):
	print(a)

def p2(a, b):
	print(a, b)
(n, k) = ninp()
ans = -1298371928379123123
for i in range(n):
	(f, t) = ninp()
	if t > k:
		f = f - (t - k)
	ans = max(ans, f)
print(ans)


(n, k) = [int(i) for i in input().split()]
c = -10 ** 9
for i in range(n):
	(f, t) = [int(i) for i in input().split()]
	if t > k:
		d = f - (t - k)
	else:
		d = f
	if d > c:
		c = d
print(c)


(n, k) = map(int, input().split(' '))
res = -100000000000
for i in range(n):
	(f, t) = map(int, input().split(' '))
	if t > k:
		res = max((f - (t - k), res))
	else:
		res = max(f, res)
print(res)


string = input()
numbers = string.split(' ')
n = int(numbers[0])
k = int(numbers[1])
values = []
for x in range(n):
	string = input()
	numbers = string.split(' ')
	a = int(numbers[0])
	b = int(numbers[1])
	if b > k:
		a -= b - k
	values.append(a)
print(max(values))


(n, m) = map(int, input().split())
z = []
for i in range(n):
	(p, t) = map(int, input().split())
	q = m - t
	if q < 0:
		p += q
	z.append(p)
print(max(z))


(n, k) = input().split(' ')
n = int(n)
k = int(k)
ans = -999999999999999
for i in range(n):
	c = [int(i) for i in input().split(' ')]
	if c[1] > k:
		ans = max(ans, c[0] - (c[1] - k))
	else:
		ans = max(ans, c[0])
print(ans)


(n, k) = map(int, input().split())
m = -10 ** 9
for _ in range(n):
	(f, t) = map(int, input().split())
	if k - t < 0:
		f -= t - k
	if f > m:
		m = f
print(m)


(x, y) = map(int, input().split())
ans = -100000000000
for i in range(x):
	(a, b) = map(int, input().split())
	ans = max(ans, min(a, a - b + y))
print(ans)


import math
(n, k) = map(int, input().split())
ans = -math.inf
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		ans = max(ans, f - (t - k))
	else:
		ans = max(ans, f)
print(ans)


(n, k) = [int(i) for i in input().split()]
(f, t) = [int(i) for i in input().split()]
if t > k:
	maxim = f + k - t
else:
	maxim = f
for i in range(1, n):
	(f, t) = [int(i) for i in input().split()]
	if t > k:
		if maxim < f + k - t:
			maxim = f + k - t
	elif maxim < f:
		maxim = f
print(maxim)


val_i = list(map(int, input().split(' ')))
b = 0
mej = 0
for x in range(val_i[0]):
	rest = list(map(int, input().split(' ')))
	if b == 0:
		if rest[1] > val_i[1]:
			mej = rest[0] - (rest[1] - val_i[1])
		else:
			mej = rest[0]
		b = 1
	elif rest[1] > val_i[1]:
		mej = max(mej, rest[0] - (rest[1] - val_i[1]))
	else:
		mej = max(mej, rest[0])
print(mej)


(n, k) = list(map(int, input().split()))
(f, t) = list(map(int, input().split()))
joy = f
if t > k:
	joy += k - t
for _ in range(n - 1):
	(f, t) = list(map(int, input().split()))
	if t > k:
		joy = max(joy, f + k - t)
	else:
		joy = max(joy, f)
print(joy)


(n, k) = map(int, input().split())
best = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if b > k:
		if best == 0:
			best = a - (b - k)
		else:
			best = max(best, a - (b - k))
	elif best == 0:
		best = a
	else:
		best = max(best, a)
print(best)


import sys
(n, k) = map(int, sys.stdin.readline().split(' '))
mx = -1000000000
while n > 0:
	(f, t) = map(int, sys.stdin.readline().split(' '))
	mx = max(mx, min(f, f - (t - k)))
	n -= 1
print(mx)


(n, k) = map(int, input().split())
joy = -2000000000
for x in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		if joy < f - (t - k):
			joy = f - (t - k)
		else:
			continue
	elif joy < f:
		joy = f
	else:
		continue
print(joy)


import sys

def get_ints():
	arr = list(map(int, sys.stdin.readline().strip().split()))
	return (arr[0], arr[1])
(n, k) = get_ints()
mej = -1e+18
for x in range(n):
	(f, t) = get_ints()
	if t > k:
		mej = max(mej, f - (t - k))
	else:
		mej = max(mej, f)
print(mej)


c = -9999999999999
(n, k) = map(int, input().split())
for i in range(n):
	(a, b) = map(int, input().split())
	if b > k:
		a -= b - k
	c = max(a, c)
print(c)


(n, k) = [int(num) for num in input().split(' ')]
ans = -1
for i in range(n):
	(f, t) = [int(num) for num in input().split(' ')]
	score = f
	if t > k:
		score = f - (t - k)
	if i == 0:
		ans = score
	else:
		ans = max(ans, score)
print(ans)


(n, k) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
joy = -float('inf')
for i in arr:
	if i[1] <= k:
		tempjoy = i[0]
	else:
		tempjoy = i[0] - (i[1] - k)
	if tempjoy > joy:
		joy = tempjoy
print(joy)


a = list(map(int, input().split()))
print(max(map(lambda x: x[0] + min(a[1] - x[1], 0), [list(map(int, input().split())) for i in range(a[0])])))


import sys
my_file = sys.stdin
num = [int(i) for i in my_file.readline().strip('\n').split(' ')]
n = num[0]
k = num[1]
rest = []
max = -1000000000
for i in my_file.readlines():
	rest = [int(k) for k in i.strip('\n').split(' ')]
	if rest[0] > max:
		if rest[1] <= k:
			max = rest[0]
		elif rest[0] - (rest[1] - k) > max:
			max = rest[0] - (rest[1] - k)
print(max)


(n, k) = (int(x) for x in input().split())
(f, t) = (int(x) for x in input().split())
if t > k:
	maxF = f - (t - k)
else:
	maxF = f
for i in range(1, n):
	(f, t) = (int(x) for x in input().split())
	if t > k:
		fun = f - (t - k)
	else:
		fun = f
	if fun > maxF:
		maxF = fun
print(maxF)


(n, k) = map(int, input().split())
z = float('-inf')
for i in range(n):
	(a, b) = map(int, input().split())
	if b > k:
		t = a - (b - k)
	else:
		t = a
	z = max(z, t)
print(z)


import sys
(n, k) = map(int, input().split())
joy = -sys.maxsize
for _ in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		temp_joy = f - (t - k)
	else:
		temp_joy = f
	if temp_joy > joy:
		joy = temp_joy
print(joy)


(n, k) = map(int, input().split())
d = sorted([list(map(int, input().split())) for i in range(n)])
ans = []
for i in d:
	[x, y] = i
	z = y - k
	if z < 0:
		z = 0
	ans.append(x - z)
print(max(ans))


(n, k) = map(int, input().strip().split())
maxJoy = -10 ** 9
for _ in range(n):
	(f, t) = map(int, input().strip().split())
	if t > k:
		joy = f - (t - k)
	else:
		joy = f
	if joy > maxJoy:
		maxJoy = joy
print(maxJoy)


import sys

def data():
	return sys.stdin.readline().strip()

def sp():
	return map(int, data().split())

def l():
	return list(sp())
temp = l()
n = temp[0]
k = temp[1]
res = []
for i in range(n):
	res.append(l())
scores = []
for (index, value) in enumerate(res):
	f = value[0]
	t = value[1]
	if t > k:
		joy = f - (t - k)
	else:
		joy = f
	scores.append(joy)
print(max(scores))


import sys, math, collections
from collections import defaultdict

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w')

def get_array():
	l = list(map(int, input().split()))
	return l

def get_2_ints():
	(a, b) = map(int, input().split())
	return (a, b)

def get_3_ints():
	(a, b, c) = map(int, input().split())
	return (a, b, c)

def sod(n):
	(n, c) = (str(n), 0)
	for i in n:
		c += int(i)
	return c

def getFloor(A, x):
	(left, right) = (0, len(A) - 1)
	floor = -1
	while left <= right:
		mid = (left + right) // 2
		if A[mid] == x:
			return A[mid]
		elif x < A[mid]:
			right = mid - 1
		else:
			floor = A[mid]
			left = mid + 1
	return floor

def main():
	(n, k) = get_2_ints()
	ans = float('-inf')
	for tt in range(n):
		(a, b) = get_2_ints()
		if b > k:
			temp = a - (b - k)
		else:
			temp = a
		ans = max(ans, temp)
	print(ans)
main()


(n, k) = map(int, input().split())
f = t = 0
maxf = -1000000000
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		f -= t - k
	if f > maxf:
		maxf = f
print(maxf)


i = input().split()
(n, k) = (int(i[0]), int(i[1]))
max_joy = -1000000000
while n > 0:
	i = input().split()
	(fi, ti) = (int(i[0]), int(i[1]))
	joy = 0
	if ti > k:
		joy = fi - (ti - k)
	else:
		joy = fi
	if joy > max_joy:
		max_joy = joy
	n -= 1
print(max_joy)


(n, k) = map(int, input().split())
j = 0
v = []
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		j = f - (t - k)
	else:
		j = f
	v.append(j)
print(max(v))


(a, b) = map(int, input().split())
(c, d) = map(int, input().split())
if d > b:
	magi = c - (d - b)
else:
	magi = c
a -= 1
i = 1
while i <= a:
	(c, d) = map(int, input().split())
	if d > b:
		mang = c - (d - b)
	else:
		mang = c
	if mang > magi:
		magi = mang
	i += 1
print(magi)


from math import *
maxx = -1000000000.0
(n, k) = map(int, input().split())
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		joy = f - t + k
	else:
		joy = f
	maxx = max(maxx, joy)
print(maxx)


def dinners(lst1, lst2, k):
	maximum = -10 ** 9 + 1
	for i in range(len(lst1)):
		if lst2[i] > k:
			if lst1[i] - (lst2[i] - k) > maximum:
				maximum = lst1[i] - (lst2[i] - k)
		elif lst1[i] > maximum:
			maximum = lst1[i]
	return maximum
(n, k_1) = [int(j) for j in input().split()]
(a, b) = (list(), list())
for z in range(n):
	(f, t) = [int(y) for y in input().split()]
	a.append(f)
	b.append(t)
print(dinners(a, b, k_1))


(n, k) = map(int, input().split())
ans = -10 ** 9
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		temp = f - (t - k)
	else:
		temp = f
	if temp > ans:
		ans = temp
print(ans)


(n, k) = map(int, input().split())
(f, t) = ([], [])
for i in range(n):
	(x, y) = map(int, input().split())
	f.append(x)
	t.append(y)
t = [x for (_, x) in sorted(zip(f, t))]
f = sorted(f)
ans = -1000000000
for i in range(n - 1, -1, -1):
	val = 0
	if t[i] > k:
		val = f[i] - (t[i] - k)
	else:
		val = f[i]
	if val > ans:
		ans = val
print(ans)


(n, k) = map(int, input().split())
out = -10 ** 10
for _ in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		z = f - (t - k)
	else:
		z = f
	out = max(out, z)
print(out)


(n, k) = map(int, input().split())
(a, b) = map(int, input().split())
if b > k:
	max = a - (b - k)
else:
	max = a
for i in range(n - 1):
	(a, b) = map(int, input().split())
	c = 0
	if b > k:
		c = a - (b - k)
	else:
		c = a
	if c > max:
		max = c
print(max)


(n, k) = map(int, input().split())
a = []
b = []
l = []
m = []
for _ in range(n):
	(f, t) = map(int, input().split())
	if t < k:
		m.append(f)
		a.append(f)
		b.append(t)
	else:
		a.append(f)
		b.append(t)
for i in range(n):
	if b[i] >= k:
		v = a[i] - (b[i] - k)
		l.append(v)
if len(m) == 0:
	print(max(l))
elif len(l) == 0:
	print(max(m))
else:
	x = max(m)
	y = max(l)
	if x > y:
		print(x)
	elif y > x:
		print(y)
	else:
		print(x)


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(sys.stdin.readline())
	if number_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
mod = 100000007
(n, k) = vary(2)
ans = -99999999999999
for i in range(n):
	(enj, time) = vary(2)
	ans = max(ans, enj - (time - k) if time > k else enj)
print(ans)


(n, k) = map(int, input().strip().split())
maxJoy = -999999999999999
for i in range(n):
	(f, t) = map(int, input().strip().split())
	if t > k:
		f -= t - k
	maxJoy = max(maxJoy, f)
print(maxJoy)


nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]
myarr = []
res = []
for i in range(0, n):
	temp = list(map(int, input().split()))
	myarr.append(temp)
for val in myarr:
	if val[1] > k:
		res.append(val[0] - (val[1] - k))
	else:
		res.append(val[0])
print(max(res))


(n, k) = map(int, input().split())
M = -99999999999
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		f -= t - k
	M = max(f, M)
print(M)


(n, k) = map(int, input().split())
L = []
for i in range(n):
	L.append(list(map(int, input().split())))
gm = 0
for i in range(n):
	if L[i][1] <= k:
		lm = L[i][0]
	else:
		lm = L[i][0] - (L[i][1] - k)
	if i == 0:
		gm = lm
	if lm > gm:
		gm = lm
print(gm)


(n, d) = input().split()
n = int(n)
d = int(d)
f = [0] * n
t = [0] * n
for i in range(n):
	(a, b) = input().split()
	f[i] = int(a)
	t[i] = int(b)
m = -1000000000
for i in range(0, n):
	if t[i] <= d:
		m = max(m, f[i])
	else:
		m = max(m, f[i] - (t[i] - d))
print(m)


(n, k) = map(int, input().split())
for i in range(n):
	(x, y) = map(int, input().split())
	if y >= k:
		if i == 0:
			t = x - (y - k)
		else:
			t = max(t, x - (y - k))
	elif i == 0:
		t = x
	else:
		t = max(t, x)
print(t)


(n, k) = map(int, input().split())
(f, t) = map(int, input().split())
if t > k:
	maxi = f - (t - k)
else:
	maxi = f
for _ in range(n - 1):
	(f, t) = map(int, input().split())
	if t > k:
		value = f - (t - k)
	else:
		value = f
	maxi = max(maxi, value)
print(maxi)


(n, k) = map(int, input().split())
joy = []
for i in range(n):
	l = list(map(int, input().split()))
	a = l[0] - l[1] + k if l[1] > k else l[0]
	joy.append(a)
print(max(joy))


(n, k) = map(int, input().split())
lr = []
while n:
	(f, t) = map(int, input().split())
	if t - k > 0:
		lr.append(f - (t - k))
	else:
		lr.append(f)
	n -= 1
print(max(lr))


cases = [int(i) for i in str(input()).split()]
joy = []
for i in range(cases[0]):
	joyi = [int(i) for i in str(input()).split()]
	if joyi[1] - cases[1] > 0:
		joy.append(joyi[0] - (joyi[1] - cases[1]))
	else:
		joy.append(joyi[0])
print(max(joy))


import sys
(n, k) = [int(item) for item in input().split()]
joy = -sys.maxsize
for i in range(n):
	(f, t) = [int(item) for item in input().split()]
	if t > k:
		tmpJoy = f - (t - k)
	else:
		tmpJoy = f
	if tmpJoy > joy:
		joy = tmpJoy
print(joy)


(n, k) = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(n)]
for d in data:
	if d[1] > k:
		d[0] -= d[1] - k
data.sort(key=lambda x: x[0], reverse=True)
print(data[0][0])


def lunch_rush(k, array):
	for i in array:
		if i[1] > k:
			i[0] = i[0] - (i[1] - k)
	array = sorted(array, reverse=True)
	print(array[0][0])
(n, k) = input().split()
array = list()
for i in range(int(n)):
	a = [int(x) for x in input().split()]
	array.append(a)
lunch_rush(int(k), array)


(n, k) = map(int, input().split(' '))
res = -2000000000.0
for i in range(n):
	(a, b) = map(int, input().split(' '))
	if b < k and a > res:
		res = a
	if b >= k and a - b + k > res:
		res = a - b + k
print(res)


str = input('')
str = str.split()
n = int(str[0])
k = int(str[1])
ans = -10000000000
for i in range(0, n):
	str = input('')
	str = str.split()
	joy = int(str[0])
	cost = int(str[1])
	tempans = 0
	if cost > k:
		tempans = joy - cost + k
	else:
		tempans = joy
	if tempans > ans:
		ans = tempans
print(ans)


(n, k) = map(int, input().split())
e = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if b > k:
		if e == 0:
			e = 1
			r = a - (b - k)
		else:
			r = max(r, a - (b - k))
	elif e == 0:
		e = 1
		r = a
	else:
		r = max(r, a)
print(r)


(n, k) = map(int, input().split())
best = -1000000000.0
for i in range(n):
	(f, t) = map(int, input().split())
	joy = f
	if t > k:
		joy = f - (t - k)
	best = max(best, joy)
print(best)


(a, b) = map(int, input().split())
k = list()
for i in range(a):
	(x, y) = map(int, input().split())
	if y > b:
		k.append(x - (y - b))
	else:
		k.append(x)
print(max(k))


def solution():
	(n, k) = map(int, input().split())
	mx = float('-Inf')
	for i in range(n):
		(f, t) = map(int, input().split())
		curr = min(f, f - (t - k))
		mx = max(curr, mx)
	print(mx)
	return
solution()


(n, k) = map(int, input().split())
p = 0
c = 0
ans = -10000000001
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		s = f - (t - k)
	else:
		s = f
	ans = max(ans, s)
print(ans)


(n, k) = [int(item) for item in input().split()]
f = []
t = []
c = []
joy = []
for i in range(n):
	(a, b) = [int(item) for item in input().split()]
	f.append(a)
	t.append(b)
for i in range(len(t)):
	if t[i] <= k:
		c.append(f[i])
	else:
		joy.append(f[i] - t[i] + k)
if c != [] and joy != []:
	max1 = max(c)
	max2 = max(joy)
	if max1 > max2:
		print(max1)
	else:
		print(max2)
elif c == []:
	print(max(joy))
elif joy == []:
	print(max(c))


(n, k) = [int(x) for x in input().split()]
maxJoy = -1000000000
for i in range(0, n):
	(f, t) = [int(x) for x in input().split()]
	if t > k:
		f -= t - k
	if f > maxJoy:
		maxJoy = f
print(maxJoy)


x = [int(item) for item in input().split()]
n = x[0]
k = x[1]
y = []
anslist = []
for s in range(n):
	y = [int(item) for item in input().split()]
	if y[1] > k:
		fun = y[0] - y[1] + k
	else:
		fun = y[0]
	anslist.append(fun)
print(max(anslist))


(n, k) = map(int, input().split())
s = -10000000000
for _ in range(n):
	(f, t) = map(int, input().split())
	if t - k > 0:
		f = f - (t - k)
		s = max(f, s)
	else:
		s = max(f, s)
print(s)


(n, k) = map(int, input().split())
ans = -100000000000000
for x in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		joy = f - (t - k)
	else:
		joy = f
	ans = max(ans, joy)
print(ans)


import math
(n, k) = list(map(int, input().split()))
arr = []
for i in range(n):
	(f, t) = list(map(int, input().split()))
	arr.append([f, t])
ans = -1 * math.inf
for pair in arr:
	(f, t) = pair
	if t > k:
		ans = max(ans, f - t + k)
	else:
		ans = max(ans, f)
print(ans)


import sys
(n, k) = map(int, sys.stdin.readline().split())
joy = -10 ** 9
for _ in range(n):
	(f, t) = map(int, sys.stdin.readline().split())
	if t <= k:
		joy = max(joy, f)
	else:
		joy = max(joy, f - (t - k))
print(joy)


(num_restaurants, max_time) = map(int, input().split())
(joy, time) = map(int, input().split())
max_joy = joy if time <= max_time else joy - time + max_time
for _ in range(num_restaurants - 1):
	(joy, time) = map(int, input().split())
	max_joy = max(max_joy, joy if time <= max_time else joy - time + max_time)
print(max_joy)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
ans = -10 ** 9
for _ in range(n):
	(f, t) = map(int, input().split())
	if t <= k:
		ans = max(ans, f)
	else:
		ans = max(ans, f - (t - k))
print(ans)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	(n, k) = map(int, input().split())
	joy = -INF
	for i in range(n):
		(f, t) = map(int, input().split())
		if t > k:
			f -= t - k
		joy = max(joy, f)
	print(joy)
t = 1
for _ in range(t):
	main()


from sys import stdin, stdout, stderr, setrecursionlimit
setrecursionlimit(100000)

def debug(*e):
	if not __debug__:
		print(*e, file=stderr)

def dd(*vals):
	import inspect, re
	frame = inspect.getframeinfo(inspect.stack()[1][0])
	vs = re.search('dd\\((.+)\\)', frame.code_context[0]).group(1).split(',')
	if vs:
		debug(','.join(('{0} = {1}'.format(vs[i], v) for (i, v) in enumerate(vals))))

def trace(f):

	def traced(*args, **kw):
		debug('calling {} with args {}, {}'.format(f.__name__, args, kw))
		return f(*args, **kw)
	return traced

def read():
	return stdin.readline().rstrip()

def readarr(sep=None, maxsplit=-1):
	return read().split(sep, maxsplit)

def readint():
	return int(read())

def readintarr(sep=None, maxsplit=-1):
	return [int(a) for a in readarr(sep, maxsplit)]

def write(*args, **kwargs):
	sep = kwargs.get('sep', ' ')
	end = kwargs.get('end', '\n')
	stdout.write(sep.join((str(a) for a in args)) + end)

def writearr(arr, sep=' ', end='\n'):
	stdout.write(sep.join((str(a) for a in arr)) + end)

def solv(f, t):
	global k
	return f - (t - k) if t > k else f
(n, k) = readintarr()
r = []
for _ in range(n):
	r.append(readintarr())
write(max((solv(f, t) for (f, t) in r)))


def main():
	(n, k) = map(int, input().split())
	f1 = -9999999999999
	for i in range(n):
		(f, t) = map(int, input().split())
		if t > k:
			f = f - t + k
		if f1 < f:
			f1 = f
	print(f1)
main()


(n, k) = map(int, input().split())
joy = -1000000000000000
while n > 0:
	n = n - 1
	(f, t) = map(int, input().split())
	if t <= k:
		if f > joy:
			joy = f
	elif f - (t - k) > joy:
		joy = f - (t - k)
print(joy)


def LunchRush(n, k, restaurants):
	joyFromRestaurants = []
	for r in restaurants:
		(f, t) = [int(x) for x in r.split()]
		if t > k:
			joyFromRestaurants.append(f - t + k)
		else:
			joyFromRestaurants.append(f)
	return max(joyFromRestaurants)
(n, k) = [int(x) for x in input().split()]
restaurants = []
i = 0
while i < n:
	restaurants.append(input())
	i += 1
print(LunchRush(n, k, restaurants))


(n, k) = list(map(int, input().split()))
ans = -10 ** 9
for _ in range(n):
	(f, t) = list(map(int, input().split()))
	if t > k:
		ans = max(ans, f - t + k)
	else:
		ans = max(ans, f)
print(ans)


a = input().split()
num = int(a[0])
tim = int(a[1])
l = []
for i in range(num):
	s = input().split()
	if int(s[1]) > tim:
		joy = int(s[0]) - (int(s[1]) - tim)
		l.append(joy)
	else:
		l.append(int(s[0]))
print(max(l))


(n, k) = map(int, input().split())
m = -999999999
for i in range(0, n):
	(f, t) = map(int, input().split())
	if t > k:
		f -= t - k
	if f > m:
		m = f
print(m)


(n, k) = map(int, input().split())
mx = None
global r
while n:
	n = n - 1
	(f, t) = map(int, input().split())
	if t < k:
		r = f
	else:
		r = f - (t - k)
	if mx is None:
		mx = r
	else:
		mx = max(mx, r)
print(mx)


(n, k) = map(int, input().split())
maxi = 10 ** 9 * -1
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		if f - (t - k) > maxi:
			maxi = f - (t - k)
	elif f > maxi:
		maxi = f
print(maxi)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(N, K) = map(int, input().split())
ans = float('-inf')
for i in range(N):
	(f, t) = map(int, input().split())
	if t > K:
		ans = max(ans, f - (t - K))
	else:
		ans = max(ans, f)
print(ans)


(n, k) = map(int, input().split())
h = -100000000000
for _ in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		h = max(f - t + k, h)
	else:
		h = max(f, h)
print(h)


z = list(map(int, input().split()))
arr = []
for i in range(z[0]):
	y = list(map(int, input().split()))
	if y[1] <= z[1]:
		arr.append(y[0])
	else:
		arr.append(y[0] - (y[1] - z[1]))
print(max(arr))


(n, k) = map(int, input().split())
t = -9999999999999
for i in range(n):
	(p, q) = map(int, input().split())
	if q > k:
		u = k + p - q
		t = max(t, u)
	else:
		t = max(t, p)
print(t)


(n, k) = map(int, input().split())
d = []
for i in range(n):
	l = [i for i in map(int, input().split())]
	if l[1] < k:
		d.append(l[0])
	else:
		d.append(l[0] - (l[1] - k))
print(max(d))


(n, k) = map(int, input().split())
fti = [list(map(int, input().split())) for i in range(n)]
ans = [fti[i][0] - (fti[i][1] - k) * (fti[i][1] > k) for i in range(n)]
print(max(ans))


(n, k) = map(int, input().split())
c = -999999999
while n > 0:
	n -= 1
	(f, t) = map(int, input().split())
	if t > k:
		f = f - (t - k)
	c = max(c, f)
print(c)


I = lambda : list(map(int, input().split()))
(n, k) = I()
f = [I() for i in range(n)]
print(max((v[0] if v[1] <= k else v[0] - (v[1] - k) for v in f)))


(n, k) = list(map(int, input().split()))
joy = []
for i in range(n):
	(f, t) = list(map(int, input().split()))
	joy.append(f + min(0, k - t))
print(max(joy))


def main():
	s = input()
	s = s.split()
	n = int(s[0])
	k = int(s[1])
	ans = -2000000000000000000000000000000
	while n:
		s = input()
		s = s.split()
		if int(s[1]) > k:
			x = int(s[0]) - (int(s[1]) - k)
		else:
			x = int(s[0])
		ans = max(ans, x)
		n -= 1
	print(ans)
main()


(n, k) = map(int, input().split())
a = []
b = []
for i in range(n):
	(a1, b1) = map(int, input().split())
	a.append(a1)
	b.append(b1)
if b[0] > k:
	ans = a[0] - (b[0] - k)
else:
	ans = a[0]
for i in range(1, n):
	if b[i] > k:
		temp = a[i] - (b[i] - k)
	else:
		temp = a[i]
	ans = max(ans, temp)
print(ans)


(n, k) = map(int, input().split())
m = -10 ** 11
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		f = f + k - t
	m = max(f, m)
print(m)


(N, K) = map(int, input().split())
ans = -1e+30
for i in range(N):
	(f, t) = map(int, input().split())
	ans = max(ans, f - max(0, t - K))
print(ans)


(n, k) = map(int, input().split())
(f, t) = map(int, input().split())
if t > k:
	main_fun = f + k - t
else:
	main_fun = f
for _ in range(n - 1):
	(f, t) = map(int, input().split())
	if t > k:
		fun = f + k - t
	else:
		fun = f
	if main_fun < fun:
		main_fun = fun
print(main_fun)


(n, k) = input().split()
n = int(n)
k = int(k)
l = []
for i in range(n):
	(f1, t1) = input().split()
	(f1, t1) = (int(f1), int(t1))
	if t1 > k:
		l.append(f1 - (t1 - k))
	else:
		l.append(f1)
print(max(l))


(n, k) = map(int, input().split())
max_joy = -1000000000
for _ in range(n):
	(f, t) = map(int, input().split())
	max_joy = max(max_joy, f - max(0, t - k))
print(max_joy)


(n, k) = map(int, input().split())
x = -float('inf')
for i in range(n):
	(f, t) = map(int, input().split())
	if k < t:
		j = f - (t - k)
	else:
		j = f
	if j >= x:
		x = j
print(x)


import math
(n, k) = map(int, input().split())
result = -1 * math.inf
for _ in range(n):
	(fi, ti) = map(int, input().split())
	joy = fi - (ti - k) if ti > k else fi
	result = max(result, joy)
print(result)


(n, k) = map(int, input().split())
joyt = [0] * n
for i in range(n):
	(f, t) = map(int, input().split())
	joyt[i] = f - max(0, t - k)
print(max(joyt))


def inpNum():
	return int(input())

def inpNums():
	return map(int, input().split())

def inpList():
	return list(map(int, input().split()))
(n, k) = inpNums()
mx_joy = float('-inf')
for i in range(n):
	(f, t) = inpNums()
	j = f if t < k else f - (t - k)
	mx_joy = max(mx_joy, j)
print(mx_joy)


def binNumber(n, size):
	return bin(n)[2:].zfill(size)

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(n, k) = map(int, input().split())
ma = -1e+18
for _ in range(n):
	(f, t) = map(int, input().split())
	su = 0
	if t > k:
		su = f - t + k
	else:
		su = f
	ma = max(ma, su)
print(ma)


import math
(n, k) = list(map(int, input().split()))
l = []
for i in range(n):
	l.append(input())

def joy(s: str):
	(f, t) = list(map(int, s.split()))
	if t > k:
		return f - (t - k)
	else:
		return f
min = -math.inf
for i in range(n):
	x = joy(l[i])
	if x > min:
		min = x
print(min)


(n, k) = [int(num) for num in input().split(' ')]
joy = float('-inf')
for _ in range(n):
	(f, t) = [int(num) for num in input().split(' ')]
	if t > k:
		f = f - (t - k)
	joy = max(joy, f)
print(joy)


(n, k) = map(int, input().split())
l = []
for i in range(n):
	(j, t) = map(int, input().split())
	if t >= k:
		l.append(j - t + k)
	else:
		l.append(j)
print(max(l))


(n, k) = map(int, input().split())
l = []
while n > 0:
	(y, p) = map(int, input().split())
	if p > k:
		j = y - (p - k)
	else:
		j = y
	l.append(j)
	n = n - 1
print(max(l))


(n, k) = [int(i) for i in input().split()]
max_joy = float('-inf')
for _ in range(n):
	(f, t) = [int(i) for i in input().split()]
	if t > k:
		if max_joy < f - (t - k):
			max_joy = f - (t - k)
	elif max_joy < f:
		max_joy = f
print(max_joy)


(n, k) = map(int, input().split())
m = -10 ** 18
for i in range(n):
	(a, b) = map(int, input().split())
	m = max(m, a - max(0, b - k))
print(m)


I = lambda : map(int, input().split())
(n, k) = I()
m = -10 ** 9
for _ in range(n):
	(f, t) = I()
	m = max(m, f - max(t - k, 0))
print(m)


import math

def main():
	(n, k) = map(int, input().split())
	_max = -math.inf
	for _ in range(n):
		(f, t) = map(int, input().split())
		_max = max(_max, f if t <= k else f - (t - k))
	print(_max)
main()


def solve(k, l):
	res = -1 * 1000000000.0
	for i in l:
		i = list(i)
		joy = i[0] - max(0, i[1] - k)
		res = max(res, joy)
	return res
(n, k) = map(int, input().split())
l = [map(int, input().split()) for _ in range(n)]
print(solve(k, l))


(n, k) = [int(i) for i in input().split()]
for i in range(n):
	(f, t) = [int(i) for i in input().split()]
	if i == 0:
		if t <= k:
			max_joy = f
		else:
			max_joy = f - (t - k)
	else:
		if t <= k:
			temp_joy = f
		else:
			temp_joy = f - (t - k)
		max_joy = max([max_joy, temp_joy])
print(max_joy)


(n, k) = map(int, input().split())
res = -10 ** 10
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		if f - (t - k) > res:
			res = f - (t - k)
	elif f > res:
		res = f
print(res)


(restaurantNum, givenTime) = map(int, input().split())
flag = 0
for i in range(restaurantNum):
	if flag == 0:
		(joy, time) = map(int, input().split())
		finalJoy = joy if time <= givenTime else joy - (time - givenTime)
		maxJoy = finalJoy
		flag += 1
	else:
		(joy, time) = map(int, input().split())
		finalJoy = joy if time <= givenTime else joy - (time - givenTime)
		maxJoy = finalJoy if finalJoy > maxJoy else maxJoy
print(maxJoy)


(n, k) = str(input()).split()
n = int(n)
k = int(k)
tar = -999999999
for i in range(n):
	(f, t) = str(input()).split()
	f = int(f)
	t = int(t)
	if t > k:
		tar = max(tar, f + k - t)
	else:
		tar = max(tar, f)
print(tar)


(n, k) = map(int, input().split())
(x, y) = map(int, input().split())
kayf = x - max(0, y - k)
for i in range(1, n):
	(x, y) = map(int, input().split())
	da = x - max(0, y - k)
	if da > kayf:
		kayf = da
print(kayf)


(n, k) = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(n)]
if L[0][1] > k:
	r = L[0][0] - (L[0][1] - k)
else:
	r = L[0][0]
for i in range(1, n):
	if L[i][1] > k:
		r = max(r, L[i][0] - (L[i][1] - k))
	else:
		r = max(r, L[i][0])
print(r)


(x, Max) = (list(map(int, input().split(' '))), -10000000000000)
for i in range(0, x[0]):
	(f, t) = list(map(int, input().split(' ')))
	Max = max(f - abs(t - x[1]), Max) if t > x[1] else max(Max, f)
print(Max)


def main():
	(n, k) = [int(i) for i in input().split()]
	joy = -9999999999999
	for i in range(n):
		(f, t) = [int(i) for i in input().split()]
		if t < k:
			temp = f
		elif t >= k:
			temp = f + k - t
		joy = max(joy, temp)
	print(joy)
	return 0
main()


(n, m) = map(int, input().split())
x = -10 ** 11
for i in range(n):
	(k, l) = map(int, input().split())
	if l > m:
		x = max(x, k - (l - m))
	else:
		x = max(x, k)
print(x)


(n, k) = map(int, input().split())
max_joy = -2 * 10 ** 9
for _ in range(n):
	(f, t) = map(int, input().split())
	max_joy = max(max_joy, f - (0 if t - k <= 0 else t - k))
print(max_joy)


(n, k) = (int(i) for i in input().split(' '))
maxx = float('-inf')
for i in range(n):
	(f, t) = (int(i) for i in input().split(' '))
	if t > k:
		z = f - (t - k)
	else:
		z = f
	if maxx < z:
		maxx = z
print(maxx)


def single_integer():
	return int(input())

def multi_integer():
	return map(int, input().split())

def string():
	return input()

def multi_string():
	return input().split()
(n, k) = multi_integer()
ans = float('-inf')
for i in range(n):
	(f, t) = multi_integer()
	if k > t:
		ans = max(f, ans)
	else:
		temp = f - (t - k)
		ans = max(temp, ans)
print(ans)


(n, k) = map(int, input().split())
cur_max = 0
ans = -10 ** 10
for i in range(n):
	x = list(map(int, input().split()))
	if x[1] <= k:
		cur_max = x[0]
	else:
		cur_max = x[0] - x[1] + k
	if cur_max > ans:
		ans = cur_max
print(ans)


(n, k) = map(int, input().split())
nums = []
for i in range(n):
	(a, b) = map(int, input().split())
	if b > k:
		p = a - (b - k)
	else:
		p = a
	nums.append(p)
print(max(nums))


(n, k) = map(int, input().split())
j = -1e+18
r = []
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		j = max(j, f - (t - k))
	else:
		j = max(j, f)
print(j)


(n, k) = map(int, input().split())
z = []
for i in range(n):
	(f, ti) = map(int, input().split())
	if ti <= k:
		z.append(f)
	else:
		z.append(f - (ti - k))
print(max(z))


(n, k) = map(int, input().split(' '))
list1 = []
for j in range(n):
	(f, t) = map(int, input().split(' '))
	if t >= k:
		list1.append(f - t + k)
	else:
		list1.append(f)
list1.sort()
print(list1[-1])


(n, k) = list(map(int, input().split()))
joy = 0
m = -10 ** 9
while n:
	(f, t) = list(map(int, input().split()))
	if t > k:
		j = f - (t - k)
	else:
		j = f
	m = max(j, m)
	n -= 1
print(m)


inp = list(map(int, input().split()))
n = inp[0]
k = inp[1]
r = []
for i in range(n):
	m = list(map(int, input().split()))
	f = m[0]
	t = m[1]
	if t > k:
		res = f - (t - k)
		r.append(res)
	else:
		res = f
		r.append(res)
result = max(r)
print(result)


(n, k) = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]
s = []
for i in range(len(a)):
	if a[i][1] > k:
		s.append(a[i][0] - (a[i][1] - k))
	else:
		s.append(a[i][0])
print(max(s))


(n, k) = map(int, input().split())
val = -1 * 10 ** 9
for i in range(n):
	sat = 0
	(f, t) = map(int, input().split())
	if t <= k:
		sat = f
	else:
		sat = f - (t - k)
	val = max(val, sat)
print(val)


(n, k) = map(int, input().split())
ma = -1000000000
for i in range(n):
	(a, b) = map(int, input().split())
	if b > k:
		ma = max(a - b + k, ma)
	else:
		ma = max(a, ma)
print(ma)


(n, k) = map(int, input().split())
ans = -float('inf')
for _ in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		f -= t - k
	if f > ans:
		ans = f
print(ans)


(n, t) = list(map(int, input().split()))
fo = []
for x in range(n):
	(m, v) = list(map(int, input().split()))
	if v <= t:
		fo.append(m)
	else:
		fo.append(m - (v - t))
print(max(fo))


import itertools as ittls
from collections import Counter
from pprint import pprint as pprint
import re
import math
from fractions import gcd

def sqr(x):
	return x * x

def inputarray(func=int):
	return map(func, input().split())
(n, k) = inputarray()

def inpairs():
	for _ in range(n):
		(x, y) = inputarray()
		yield (x - max(y - k, 0))
print(max(inpairs()))


import sys
(n, k) = map(int, input().split())
mj = -sys.maxsize
for _ in range(n):
	(x, y) = map(int, input().split())
	if y > k:
		if mj < x - (y - k):
			mj = x - (y - k)
	elif y <= k:
		if mj < x:
			mj = x
print(mj)


(n, k) = map(int, input().split())
for i in range(0, n):
	(a, b) = map(int, input().split())
	if b <= k:
		fun = a
	else:
		fun = a - (b - k)
	if i == 0:
		x = fun
	else:
		x = max(x, fun)
print(x)


[n, k] = [int(x) for x in input().split(' ')]
fun = []
time = []
for i in range(n):
	[f, t] = [int(x) for x in input().split(' ')]
	fun.append(f)
	time.append(t)
if time[0] < k:
	maxfun = fun[0]
else:
	maxfun = fun[0] - time[0] + k
for i in range(n):
	if time[i] > k:
		curfun = fun[i] - time[i] + k
	else:
		curfun = fun[i]
	if curfun > maxfun:
		maxfun = curfun
print(maxfun)


(n, k) = (int(i) for i in input().split())
ans = -(1 << 35)
for i in range(n):
	(f, t) = (int(i) for i in input().split())
	ans = max(ans, f - max(0, t - k))
print(ans)


(number_restaurants, time_lunch) = list(map(int, input().split(' ')))
max_joy = 0
for i in range(number_restaurants):
	(joy, time) = list(map(int, input().split(' ')))
	if time > time_lunch:
		joy = joy - (time - time_lunch)
	if joy > max_joy:
		max_joy = joy
	elif max_joy == 0:
		max_joy = joy
print(max_joy)


from sys import stdin, stdout

def solve(n, k, eats):
	maxi = -9999999999999999999999
	for res in eats:
		(f, t) = res
		if t > k:
			joy = f - (t - k)
		else:
			joy = f
		maxi = max(maxi, joy)
	return maxi
(n, k) = list(map(int, stdin.readline().rstrip().split()))
count = n
eats = []
while count:
	count -= 1
	eats.append(tuple(map(int, stdin.readline().rstrip().split())))
stdout.write(str(solve(n, k, eats)))


(n, k) = map(int, input().split())
(m, li) = (0, [])
for _ in range(n):
	(f, t) = map(int, input().split())
	li.append(f if t < k else f - (t - k))
print(max(li))


(n, k) = [int(x) for x in input().split(' ')]
c = []
fi = []
s = []
v = []
for _ in range(n):
	(a, b) = [int(y) for y in input().split(' ')]
	fi.append(a)
	c.append(b)
for i in c:
	if i <= k:
		v.append(1)
	else:
		v.append(0)
for i in range(len(v)):
	if v[i] == 1:
		s.append(fi[i])
	if v[i] == 0:
		g = fi[i] - (c[i] - k)
		s.append(g)
s.sort()
q = s[len(s) - 1]
w = s.index(q)
print(s[w])


(n, m) = map(int, input().split())
mn = -10000000000000000000000
for i in range(n):
	(a, b) = map(int, input().split())
	if b > m:
		j = a + m - b
		if j > mn:
			mn = j
	else:
		j = a
		if j > mn:
			mn = j
print(mn)


import sys
try:
	sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
	sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except Exception as e:
	pass
(n, k) = list(map(int, input().split()))
maxval = -float('inf')
for i in range(n):
	(f, t) = list(map(int, input().split()))
	maxval = max(maxval, f - (t - k) if t > k else f)
print(maxval)


mx = -1000000000
import sys
(n, k) = input().split()
n = int(n)
k = int(k)
for i in range(0, n):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	mx = max(mx, min(x, x - (y - k)))
print(mx)


(n, k) = list(map(int, input().rstrip().split()))
max = -1000000000
for i in range(n):
	(f, t) = list(map(int, input().rstrip().split()))
	if t < k:
		if max < f:
			max = f
	elif max < f - t + k:
		max = f - t + k
print(max)


(n, k) = [int(i) for i in input().split()]
maxJoy = -10 ** 9
for i in range(0, n):
	(f, t) = [int(i) for i in input().split()]
	if t <= k:
		maxJoy = max(maxJoy, f)
	else:
		maxJoy = max(maxJoy, f - t + k)
print(maxJoy)


(n, k) = input().split()
n = int(n)
k = int(k)
ans = 0
check = True
for i in range(n):
	(f, t) = input().split()
	f = int(f)
	t = int(t)
	if t > k:
		j = f - (t - k)
	else:
		j = f
	if j > ans or check:
		ans = j
		check = False
print(ans)


def lr(f, t, k):
	if t > k:
		return f - t + k
	else:
		return f

def main():
	inp = input().split()
	k = int(inp[1])
	n = int(inp[0])
	m = []
	for i in range(n):
		ii = input().split()
		fi = int(ii[0])
		ti = int(ii[1])
		m.append(lr(fi, ti, k))
	print(max(m))
main()


(n, m) = map(int, input().split())
ma = -1000000000000000000
for i in range(n):
	(a, b) = map(int, input().split())
	if b <= m:
		if ma < a:
			ma = a
	elif ma < a - b + m:
		ma = a - b + m
print(ma)


R = lambda : list(map(int, input().split()))
l = []
(n, m) = R()
for i in range(n):
	(g, h) = R()
	if h > m:
		l.append(g - (h - m))
	else:
		l.append(g)
print(max(l))


(n, k) = map(int, input().split())
max = -1000000000
for _ in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		f = f - (t - k)
		if max < f:
			max = f
	elif max < f:
		max = f
print(max)


(n, k) = map(int, input().split())
joys = []
for a in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		joys.append(f - (t - k))
	else:
		joys.append(f)
print(max(joys))


(n, k) = map(int, input().split())
print(max([(lambda x: x[0] if x[1] <= k else x[0] - (x[1] - k))(list(map(int, input().split()))) for i in range(n)]))


(n, k) = map(int, input().split())
maxx = -10000000000.0 - 1
for i in range(n):
	(f, t) = map(int, input().split())
	if t <= k:
		maxx = max(f, maxx)
	else:
		maxx = max(maxx, f - (t - k))
print(maxx)


a = [int(x) for x in input().split()]
d = []
for i in range(a[0]):
	b = [int(x) for x in input().split()]
	if b[1] > a[1]:
		d.append(b[0] - (b[1] - a[1]))
	else:
		d.append(b[0])
print(max(d))


(n, k) = map(int, input().split())
m = -10 ** 9
for i in range(n):
	(f, t) = map(int, input().split())
	m = max(m, f - max(t - k, 0))
print(m)


(n, k) = map(int, input().split(sep=' '))
set = False
max = 0
for i in range(n):
	(f, t) = map(int, input().split(' '))
	if not set:
		set = True
		if t > k:
			max = f - (t - k)
		else:
			max = f
	elif t > k:
		if max < f - (t - k):
			max = f - (t - k)
	elif max < f:
		max = f
print(max)


(a, b) = input().split()
a = int(a)
b = int(b)
x = [int(x) for x in input().split()]
if x[1] <= b:
	best = x[0]
else:
	best = x[0] - (x[1] - b)
for i in range(a - 1):
	x = [int(x) for x in input().split()]
	if x[1] <= b:
		c = x[0]
	else:
		c = x[0] - (x[1] - b)
	if c > best:
		best = c
print(best)


(n, k) = [int(a) for a in input().split()]
maxx = 10 ** 9 * -1
for _ in range(n):
	(f, t) = [int(a) for a in input().split()]
	if t > k:
		a = f - (t - k)
	else:
		a = f
	if a > maxx:
		maxx = a
if maxx != 10 ** 9 * -1:
	print(maxx)
else:
	print(-1)


(n, k) = map(int, input().split())
M = -1000000000
while n:
	(f, t) = map(int, input().split())
	if k < t:
		f -= t - k
	if f > M:
		M = f
	n -= 1
print(M)


(n, k) = map(int, input().split())
s = []
for i in range(n):
	(a, b) = map(int, input().split())
	s.append((a, b))
s.sort(key=lambda x: x[0], reverse=True)
t = []
for i in range(n):
	if s[i][1] <= k:
		t.append(s[i][0])
	else:
		t.append(s[i][0] - (s[i][1] - k))
print(max(t))


(n, k) = (int(x) for x in input().split())
val = -10 ** 9
for i in range(n):
	(f, t) = (int(x) for x in input().split())
	cur = min(f, f - (t - k))
	if cur > val:
		val = cur
print(val)


(n, k) = [int(i) for i in input().split()]
(f, t) = [int(i) for i in input().split()]
maxf = 0
cf = 0
if t > k:
	maxf = f - (t - k)
else:
	maxf = f
n = n - 1
while n:
	(f, t) = [int(i) for i in input().split()]
	if t > k:
		cf = f - (t - k)
	else:
		cf = f
	if cf > maxf:
		maxf = cf
	n = n - 1
print(maxf)


(n, t) = map(int, input().split())
k = -10000000000
for i in range(n):
	(a, b) = map(int, input().split())
	if b > t:
		k = max(k, a - b + t)
	else:
		k = max(k, a)
print(k)


def joy(f: int, t: int, k: int) -> int:
	return f - (t - k) if t > k else f
(n, k) = map(int, input().split())
joys = [0] * n
for i in range(n):
	(f, t) = map(int, input().split())
	joys[i] = joy(f, t, k)
print(max(joys))


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
(n, k) = rinput()
maxi = -999999999
for i in range(n):
	(f, t) = rinput()
	if t > k:
		maxi = max(f - t + k, maxi)
	else:
		maxi = max(f, maxi)
print(maxi)


t = input().split()
n = int(t[0])
k = int(t[1])
slon = -100000000000000
for i in range(n):
	t = input().split()
	if int(t[1]) > k:
		slon = max(slon, int(t[0]) - (int(t[1]) - k))
	else:
		slon = max(slon, int(t[0]))
print(slon)


(n, k) = map(int, input().split())
s = -9999999999999
a = 0
while n:
	(f, t) = map(int, input().split())
	a = [f - (t - k), f][t <= k]
	s = [s, a][s <= a]
	n -= 1
print(s)


(nb, k) = map(int, input().split())
ff = []
tt = []
for i in range(nb):
	(f, t) = map(int, input().split())
	tt.append(t)
	ff.append(f)
result = []
for i in range(nb):
	result.append(ff[i] + (k - tt[i]) * (tt[i] > k))
print(max(result))


def max(a, b):
	if a > b:
		return a
	else:
		return b
l = list(map(int, input().split(' ')))
(n, k, m) = (l[0], l[1], -100000000000)
for i in range(n):
	z = list(map(int, input().split(' ')))
	if z[1] > k:
		m = max(m, z[0] - (z[1] - k))
	else:
		m = max(m, z[0])
print(m)


(a, b) = map(int, input().split())
x = []
for i in range(0, a):
	(f, t) = map(int, input().split())
	if t < b:
		x.append(f)
	else:
		x.append(f + b - t)
print(max(x))


import math
import sys
import collections

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
(n, k) = mi()
m = -10 ** 9
for i in range(n):
	(f, t) = mi()
	if t > k:
		f = f - (t - k)
	m = max(m, f)
print(m)


(n, k) = input().split()
n = int(n)
k = int(k)
a = []
for i in range(n):
	a.append(tuple(map(int, input().split())))
max_joy = 0
neg_joy = -9999999999
for i in range(n):
	if k > a[i][1]:
		joy = a[i][0]
		if joy > max_joy:
			max_joy = joy
	else:
		diff = a[i][0] - (a[i][1] - k)
		if diff >= 0:
			if diff > max_joy:
				max_joy = diff
		elif diff < 0:
			if diff > neg_joy:
				neg_joy = diff
if max_joy == 0 and neg_joy < 0:
	print(neg_joy)
else:
	print(max_joy)


s = str(input()).split()
n = int(s[0])
k = int(s[1])
for i in range(n):
	z = str(input()).split()
	f = int(z[0])
	t = int(z[1])
	if t > k:
		x = f - t + k
	else:
		x = f
	if i == 0:
		m = x
	if x > m:
		m = x
print(m)


def getArr(n, k):
	fun = list()
	for i in range(n):
		arr = list(map(int, input().rstrip().split()))
		f = arr[0]
		t = arr[1]
		if t <= k:
			fun.append(f)
		else:
			fun.append(f - (t - k))
	return fun
arr = list(map(int, input().rstrip().split()))
n = arr[0]
k = arr[1]
joy = getArr(n, k)
print(max(joy))


(n, k) = input().split()
l = []
n = int(n)
k = int(k)
for i in range(0, n):
	(fi, ti) = input().split()
	if int(ti) <= k:
		l.append(int(fi))
	elif int(ti) > k:
		l.append(int(fi) - (int(ti) - k))
print(max(l))


datos = list(str(input()).split())
datos[0] = int(datos[0])
datos[1] = int(datos[1])
resultados = []
for i in range(datos[0]):
	restaurante = list(str(input()).split())
	restaurante[0] = int(restaurante[0])
	restaurante[1] = int(restaurante[1])
	if datos[1] - restaurante[1] >= 0:
		resultados.append(restaurante[0])
	else:
		resultados.append(restaurante[0] - (restaurante[1] - datos[1]))
maximo = resultados[0]
for i in resultados:
	if i > maximo:
		maximo = i
print(maximo)


(n, k) = map(int, input().split(' '))
arr = []
for i in range(n):
	t = list(map(int, input().split(' ')))
	arr.append(t)
maxjoy = -pow(10, 10)
for i in range(len(arr)):
	if arr[i][1] <= k:
		joy = arr[i][0]
	else:
		joy = arr[i][0] - (arr[i][1] - k)
	maxjoy = max(maxjoy, joy)
if maxjoy == -pow(10, 10):
	print(-1)
	exit()
print(maxjoy)


(n, k) = [int(x) for x in input().split()]
ans = -10 ** 15
for i in range(n):
	(f, t) = [int(x) for x in input().split()]
	ans = max(ans, f - max(0, t - k))
print(ans)


(n, k) = list(map(int, input().split()))
x = -100000000000000
for i in range(n):
	(f, t) = list(map(int, input().split()))
	if t > k:
		x = max(x, f + k - t)
	else:
		x = max(x, f)
print(x)


(n, k) = map(int, input().split())
joy = [None] * 100000
time = [None] * 100000
for i in range(0, n):
	(joy[i], time[i]) = map(int, input().split())
ans = -2000000000.0
for i in range(0, n):
	cur = 0
	if time[i] > k:
		cur = joy[i] - time[i] + k
	else:
		cur = joy[i]
	ans = max(ans, cur)
print(ans)


(n, k) = [*map(int, input().split())]
a = [[*map(int, input().split())] for i in range(n)]
print(max([*map(lambda x: x[0] - max(0, x[1] - k), a)]))


from sys import stdin, stdout

def stdinhack():
	for line in stdin:
		yield line
next_line = lambda : next(stdinhack()).split()
write = lambda x: stdout.write(x)

def solve():
	(n, k) = map(int, next_line())
	mx = -10000000000.0
	for _ in range(n):
		(f, t) = map(int, next_line())
		mx = max(mx, f - (t - k) if t > k else f)
	print(mx)
	return
solve()


(n, k) = map(int, input().split())
array = []
c = []
for i in range(n):
	array.append(list(map(int, input().split())))
for i in range(n):
	if array[i][1] > k:
		d = array[i][0] - array[i][1] + k
		c.append(d)
	else:
		c.append(array[i][0])
print(max(c))


(n, k) = map(int, input().split())
i = 0
ples = -1000000000
while i < n:
	(f, t) = map(int, input().split())
	if t > k:
		ples = max(ples, f + k - t)
	else:
		ples = max(ples, f)
	i += 1
print(ples)


(n, k) = input().split()
ans = -1000000001
for i in range(0, int(n)):
	(f, t) = input().split()
	if int(t) > int(k):
		temp = int(f) - (int(t) - int(k))
	else:
		temp = int(f)
	ans = max(ans, temp)
print(ans)


import sys
from math import *
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
ls = lambda : list(input().strip())
from collections import defaultdict as df
import heapq
infinite = float('inf')
(n, k) = RI()
maxo = -1000000005
for i in range(n):
	(f, t) = RI()
	temp = min(f, f - (t - k))
	maxo = max(temp, maxo)
print(maxo)


import sys
from os import path
if path.exists('input.txt') and path.exists('output.txt'):
	sys.stdout = open('output.txt', 'w')
	sys.stdin = open('input.txt', 'r')

def main():
	(n, k) = (int(i) for i in input().split())
	mx = -1000000005
	for ii in range(n):
		(f, t) = (int(i) for i in input().split())
		if t > k:
			mx = max(mx, f - (t - k))
		else:
			mx = max(mx, f)
	print(mx)
main()


(n, k) = map(int, input().split())
l = []
while n:
	(f, t) = map(int, input().split())
	if t > k:
		l.append(f - (t - k))
	else:
		l.append(f)
	n = n - 1
print(max(l))


(n, k) = list(map(int, input().split()))
max_n = -10000000022
for i in range(n):
	(f, t) = list(map(int, input().split()))
	cur = f - max(0, t - k)
	if cur > max_n:
		max_n = cur
print(max_n)


(x, y) = [int(a) for a in input().split()]
z = []
for i in range(x):
	(a, b) = [int(j) for j in input().split()]
	if b > y:
		z.append(a - (b - y))
	else:
		z.append(a)
print(max(z))


n_k = [int(x) for x in input('').split()]
(n, k) = n_k
happiness = []
maxf = -9999999999
for i in range(n):
	f_t = [int(x) for x in input('').split()]
	(f, t) = f_t
	f = f if t <= k else f - (t - k)
	maxf = f if f > maxf else maxf
print(maxf)


(n, k) = input().split()
n = int(n)
k = int(k)
max = -9999999999999999
for i in range(n):
	(f, t) = input().split()
	f = int(f)
	t = int(t)
	if t > k:
		max = max if max > f - t + k else f - t + k
	else:
		max = max if max > f else f
print(max)


(n, m) = map(int, input().split())
(f, t) = map(int, input().split())
if t > m:
	c = f - (t - m)
else:
	c = f
for i in range(1, n):
	(f, t) = map(int, input().split())
	if t > m:
		if f - (t - m) > c:
			c = f - (t - m)
	elif f > c:
		c = f
print(c)


(n, k) = list(map(int, input().split()))
c = []
for i in range(n):
	(f, t) = list(map(int, input().split()))
	c.append((f - (t - k), f)[t <= k])
print(max(c))


import heapq
import math
(n, k) = map(int, input().split())
ma = -math.inf
for _ in range(n):
	(f, t) = map(int, input().split())
	if t < k:
		pass
	else:
		f = f - (t - k)
	ma = max(ma, f)
print(ma)


(n, k) = map(int, input().split())
res = -1000000000000000.0
for _ in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		res = max(res, f - (t - k))
	else:
		res = max(res, f)
print(res)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().split(' ')))
(n, k) = read()
ans = -float('inf')
for i in range(n):
	(f, t) = read()
	ans = max(ans, [f, f - (t - k)][t > k])
print(ans)


import math

def solve(n, k):
	maximum_joy = -math.inf
	while n:
		(f, t) = list(map(int, input().strip().split()))
		if t < k:
			maximum_joy = max(maximum_joy, f)
		else:
			maximum_joy = max(maximum_joy, f - t + k)
		n -= 1
	return maximum_joy
(n, k) = list(map(int, input().strip().split()))
result = solve(n, k)
print(result)


(n, c) = input().split(' ')
n = int(n)
c = int(c)
a = []
b = []
for i in range(n):
	a.append([])
	k = input().split(' ')
	for j in range(2):
		a[i].append(int(k[j]))
for i in range(n):
	if a[i][1] - c <= 0:
		b.append(a[i][0])
	else:
		a[i][0] = a[i][0] - (a[i][1] - c)
		b.append(a[i][0])
print(max(b))


(n, k) = map(int, input().split())
j = []
for i in range(n):
	(x, y) = map(int, input().split())
	if y > k:
		j.append(x + k - y)
	else:
		j.append(x)
print(max(j))


(n, k) = [int(i) for i in input().split()]
maxim = -9999999999999999
for i in range(0, n):
	ls = [int(i) for i in input().split()]
	if ls[1] > k:
		maxim = max(ls[0] - (ls[1] - k), maxim)
	else:
		maxim = max(maxim, ls[0])
print(maxim)


def joy(f, t, k):
	return f if t <= k else f - (t - k)

def main():
	[n, k] = [int(_) for _ in input().split()]
	[f, t] = [int(_) for _ in input().split()]
	max_joy = joy(f, t, k)
	for _ in range(n - 1):
		[f, t] = [int(_) for _ in input().split()]
		max_joy = max(max_joy, joy(f, t, k))
	print(max_joy)
main()


(N, K) = map(int, input().split())
lst = []
for i in range(N):
	(a1, a2) = map(int, input().split())
	joy1 = 0
	if a2 > K:
		joy1 = a1 - (a2 - K)
	else:
		joy1 = a1
	lst.append(joy1)
print(max(lst))


(n, k) = [int(i) for i in input().split()]
lst = []
while n:
	n -= 1
	(f, t) = [int(i) for i in input().split()]
	if t > k:
		lst.append(f - (t - k))
	else:
		lst.append(f)
print(max(lst))


yo = list(map(int, input().split()))
n = yo[0]
k = yo[1]
maxa = -10 ** 10
for i in range(n):
	x = list(map(int, input().split()))
	if x[1] > k:
		ro = x[0] - (x[1] - k)
	else:
		ro = x[0]
	if ro > maxa:
		maxa = ro
print(maxa)


(x, y) = [int(a) for a in input().split()]
ar = []
for i in range(0, x):
	(n, m) = [int(a) for a in input().split()]
	if m > y:
		s = n - (m - y)
	else:
		s = n
	ar.append(s)
f = max(ar)
print(f)


inp = list(map(int, input().split()))
(n, k) = inp
maxi = -9999999999999999999999999
for _ in range(n):
	a = list(map(int, input().split()))
	(f, t) = a
	if t >= k:
		maxi = max(maxi, f - (t - k))
	else:
		maxi = max(maxi, f)
print(maxi)


(n, k) = map(int, input().split())
(f, t) = map(int, input().split())
maxjoy = min(f - (t - k), f)
for i in range(1, n):
	(f, t) = map(int, input().split())
	score = min(f - (t - k), f)
	if score > maxjoy:
		maxjoy = score
print(maxjoy)


import sys

def main():
	(restaurant, time) = map(int, sys.stdin.readline().split())
	res = None
	for i in range(restaurant):
		(joy, time_need) = map(int, sys.stdin.readline().split())
		if time_need <= time:
			res = max(res, joy) if res is not None else joy
		else:
			current = joy - (time_need - time)
			res = max(res, current) if res is not None else current
	print(res)
main()


inp = list(map(int, input().split()))
(num, time) = (inp[0], inp[1])
lis = []
hap = -100000000000000000
for x in range(num):
	temp = list(map(int, input().split()))
	lis.append(temp)
for x in lis:
	temp = x[0] - (x[1] - time)
	if x[1] <= time and hap < x[0]:
		hap = x[0]
	if temp > hap and x[1] > time:
		hap = temp
print(hap)


(a, b) = input().split()
li = []
for i in range(int(a)):
	(c, d) = input().split()
	if int(d) <= int(b):
		li.append(int(c))
	else:
		li.append(int(c) - (int(d) - int(b)))
if li == []:
	print(-1)
else:
	print(max(li))


(n, k) = list(map(int, input().split()))
b = []
for x in range(n):
	(f, t) = list(map(int, input().split()))
	if t > k:
		s = f - (t - k)
		b.append(s)
	else:
		s = f
		b.append(s)
print(max(b))


import sys
(n, k) = map(int, input().split())
ans = -sys.maxsize
for i in range(n):
	(f, t) = map(int, input().split())
	if t <= k:
		if f > ans:
			ans = f
	else:
		a = f - (t - k)
		if a > ans:
			ans = a
print(ans)


(n, k) = (int(x) for x in input().split())
val = -float('inf')
for i in range(n):
	(f, t) = (int(x) for x in input().split())
	cur = min(f, f - (t - k))
	val = max(val, cur)
print(val)


(t, k) = map(int, input().split())
joy = 0
ma = -1000000000
for i in range(t):
	(f, ti) = map(int, input().split())
	if ti > k:
		joy = f - (ti - k)
	else:
		joy = f
	ma = max(joy, ma)
print(ma)


(n, k) = map(int, input().split())
gj = -10000000000
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		f = f - t + k
	if f > gj:
		gj = f
print(gj)


(n, t) = map(int, input().split())
li = []
for i in range(n):
	(f, t1) = map(int, input().split())
	if t1 > t:
		li.append(f + t - t1)
	else:
		li.append(f)
print(max(li))


from math import inf
(n, k) = [int(x) for x in input().split()]
pleasure = -inf
for _ in range(n):
	(f, t) = [int(x) for x in input().split()]
	new_pleasure = f
	if t > k:
		new_pleasure -= t - k
	if new_pleasure > pleasure:
		pleasure = new_pleasure
print(pleasure)


(n, k) = map(int, input().split())
rest = []
for cont in range(0, n):
	l = list(map(int, input().split()))
	rest.append(l)
maxjoy = -9999999999999999
for r in rest:
	if r[1] > k:
		joy = r[0] - r[1] + k
	else:
		joy = r[0]
	if joy > maxjoy:
		maxjoy = joy
print(maxjoy)


(a, b) = map(int, input().rstrip().split(' '))
max_joy = -999999999999999999
while a:
	(f, t) = map(int, input().rstrip().split(' '))
	if t > b:
		joy = f - (t - b)
	else:
		joy = f
	if joy > max_joy:
		max_joy = joy
	a -= 1
print(max_joy)


while 1:
	try:
		data1 = [int(i) for i in input().split(' ')]
		how_many_data = data1[0]
		coach_time = data1[1]
		max_joy = 'Null'
		for times in range(how_many_data):
			data2 = [int(i) for i in input().split(' ')]
			restaurant_joy = data2[0]
			restaurant_time = data2[1]
			time_diff = restaurant_time - coach_time
			if time_diff > 0:
				current_joy = restaurant_joy - time_diff
			else:
				current_joy = restaurant_joy
			if max_joy == 'Null':
				max_joy = current_joy
			else:
				max_joy = max(max_joy, current_joy)
		print(max_joy)
	except:
		break


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, m) = LI()
	aa = [LI() for _ in range(n)]
	r = -inf
	for (f, t) in aa:
		k = f + min(0, m - t)
		if r < k:
			r = k
	return r
print(main())


(n, k) = map(int, input().split())
arr = [tuple(map(int, input().split())) for i in range(n)]
print(max([i[0] if k >= i[1] else i[0] - i[1] + k for i in arr]))


(n, k) = [int(i) for i in input().split()]
l = []
for i in range(n):
	s = 0
	(f, t) = [int(i) for i in input().split()]
	if t > k:
		s = f - (t - k)
		l.append(s)
	else:
		l.append(f)
print(max(l))


ch = input()
l = [int(i) for i in ch.split(' ')]
(n, k) = (l[0], l[-1])
fh = input()
mh = [int(i) for i in fh.split(' ')]
(f, t) = (mh[0], mh[-1])
if t > k:
	maxj = f - (t - k)
else:
	maxj = f
for j in range(1, n):
	sh = input()
	m = [int(i) for i in sh.split(' ')]
	(f, t) = (m[0], m[-1])
	if t > k:
		j = f - (t - k)
	else:
		j = f
	if j > maxj:
		maxj = j
print(maxj)


from sys import stdin, stdout
input = stdin.readline
(n, k) = map(int, input().split())
ma = -float('inf')
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		ma = max(f - t + k, ma)
	else:
		ma = max(f, ma)
stdout.write(str(ma))


[n, k] = [int(i) for i in input().split()]
joy = 0
for x in range(n):
	[f, t] = [int(j) for j in input().split()]
	if x == 0:
		joy = f - max(t - k, 0)
	else:
		joy = max(joy, f - max(t - k, 0))
print(joy)


s = input()
l = []
l = s.split()
n = int(l[0])
k = int(l[1])
d = []
for i in range(0, n):
	r = input()
	w = []
	w = r.split()
	fi = int(w[0])
	ti = int(w[1])
	if ti > k:
		m = 0
		m = fi - (ti - k)
		d.append(m)
	else:
		d.append(fi)
print(max(d))


(n, k) = map(int, input().split())
(l, d) = ([], [])
for u in range(n):
	(x, y) = map(int, input().split())
	l.append(x)
	d.append(y)
m = -10 ** 9
for i in range(n):
	if d[i] >= k:
		s = l[i] - (d[i] - k)
	else:
		s = l[i]
	if s > m:
		m = s
print(m)


(n, k) = map(int, input().split())
q = []
for i in range(n):
	(x, y) = map(int, input().split())
	if y > k:
		q.append(x - (y - k))
	else:
		q.append(x)
q.sort()
print(q[-1])


(a, b) = map(int, input().strip().split())
joy = []
for _ in range(a):
	(j, t) = map(int, input().split())
	if t < b:
		joy.append(j)
	else:
		joy.append(j - t + b)
print(max(joy))


(n, k) = map(int, input().split())
ma = -11 ** 11
for _ in range(n):
	(f, t) = map(int, input().split())
	x = f - t + k
	if t < k:
		x = f
	if x > ma:
		ma = x
print(ma)


def value(t, f, k):
	if t > k:
		return f - (t - k)
	else:
		return f

def main():
	first_line = input()
	first_line = first_line.split()
	n = int(first_line[0])
	k = int(first_line[1])
	t = []
	f = []
	for i in range(n):
		line = input()
		line = line.split()
		f += [int(line[0])]
		t += [int(line[1])]
	maximum_index = 0
	maximum = -1 * float('inf')
	for i in range(0, n):
		val = value(t[i], f[i], k)
		if val > maximum:
			maximum = val
			maximum_index = val
	print(maximum)
import doctest
doctest.testmod()
main()


from sys import stdin, stdout
from math import inf
nk = list(map(int, stdin.readline().strip().split()))
n = nk[0]
k = nk[1]
max_joy = -inf
for i in range(n):
	restt = list(map(int, stdin.readline().strip().split()))
	if restt[1] > k:
		max_joy = max(max_joy, restt[0] + k - restt[1])
	else:
		max_joy = max(restt[0], max_joy)
stdout.write(str(max_joy))


from math import inf
from builtins import int
(n, k) = input().split()
(n, k) = (int(n), int(k))
A = []
Max = -inf
for i in range(0, n):
	(f, t) = input().split()
	(f, t) = (int(f), int(t))
	if t > k:
		f = f - t + k
	if f > Max:
		Max = f
print(Max)


(n, k) = map(int, input().split())
maxfun = float('-inf')
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		fun = f - (t - k)
	else:
		fun = f
	if fun > maxfun:
		maxfun = fun
print(maxfun)


(x, k) = map(int, input().strip().split())
l = []
for i in range(x):
	p = list(map(int, input().strip().split()))
	l.append(p)
j = []
for i in l:
	if i[1] > k:
		j.append(i[0] - (i[1] - k))
	else:
		j.append(i[0])
m = max(j)
print(m)


(n, k) = map(int, input().split())
res = 0
max_res = -1e+18
for i in range(n):
	(f, t) = map(int, input().split())
	if t > k:
		res = f - (t - k)
	else:
		res = f
	max_res = max(max_res, res)
print(max_res)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, k) = get_ints()
maxi = -1 * inf
for i in range(n):
	(F, T) = get_ints()
	if T <= k:
		maxi = max(maxi, F)
	else:
		maxi = max(maxi, F - (T - k))
print(maxi)


m = -float('inf')
(n, k) = [int(i) for i in input().split()]
for x in range(n):
	(a, b) = [int(i) for i in input().split()]
	j = 0
	if b > k:
		j = a - (b - k)
	else:
		j = a
	if j > m:
		m = j
print(m)


(n, k) = map(int, input().split())
r = None
for _ in [0] * n:
	(f, t) = map(int, input().split())
	a = f - (t - k) * (t > k)
	if r is None or r < a:
		r = a
print(r)


(n, k) = map(int, input().split())
l = []
for _ in range(n):
	(a, b) = map(int, input().split())
	if b > k:
		l.append(a - b + k)
	else:
		l.append(a)
print(max(l))


(n, k) = map(int, input().split())
j = -2 ** 50
for _ in range(n):
	(f, t) = map(int, input().split())
	j = max(j, f - max(t - k, 0))
print(j)


p = input().split(' ')
n = int(p[0])
k = int(p[1])
mx = -1000000009
for i in range(n):
	p = input().split(' ')
	if int(p[1]) > k:
		mx = max(mx, k + int(p[0]) - int(p[1]))
	else:
		mx = max(mx, int(p[0]))
print(mx)


(n, k) = [int(x) for x in input().split()]
joy = []
for i in range(n):
	(fi, ti) = [int(x) for x in input().split()]
	if ti > k:
		joy.append(fi - ti + k)
	else:
		joy.append(fi)
print(max(joy))