s = str(eval(input()))

ans = 1000

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

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

    ans = min(ans, abs(x-753))

print(ans)



s = eval(input())

ans = []

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

    ans.append(abs(int(s[i:i+3]) - 753))

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

s = eval(input())
ans = []
for i in range(len(s) - 2):
    ans.append(abs(int(s[i : i + 3]) - 753))
print((min(ans)))

-s = str(eval(input())) -ans = 1000 +s = eval(input()) +ans = [] -    x = int(s[i : i + 3]) -    ans = min(ans, abs(x - 753)) -print(ans) +    ans.append(abs(int(s[i : i + 3]) - 753)) +print((min(ans)))