x = 753

s = eval(input())

ans=10**10

for i in range(len(s)-2):

	if(abs(x-int(s[i:i+3]))<ans):

		ans=abs(x-int(s[i:i+3]))

print(ans)
x = 753

s = eval(input())

ans= 1000

for i in range(len(s)-2):

	if(abs(x-int(s[i:i+3]))<ans):

		ans=abs(x-int(s[i:i+3]))

print(ans)
x = 753
s = eval(input())
ans = 10**10
for i in range(len(s) - 2):
    if abs(x - int(s[i : i + 3])) < ans:
        ans = abs(x - int(s[i : i + 3]))
print(ans)

x = 753
s = eval(input())
ans = 1000
for i in range(len(s) - 2):
    if abs(x - int(s[i : i + 3])) < ans:
        ans = abs(x - int(s[i : i + 3]))
print(ans)

-ans = 10**10 +ans = 1000