s=eval(input());minn=1000

for i in range(len(s)-2):minn=min(abs(int(s[i:i+3])-753),minn)

print(minn)
s=eval(input())

n=len(s)

ans=10**10

for i in range(n-2):

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

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

print(ans)

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

s = eval(input())
n = len(s)
ans = 10**10
for i in range(n - 2):
    m = int(s[i : i + 3])
    ans = min(ans, abs(m - 753))
print(ans)

-minn = 1000 -for i in range(len(s) - 2): -    minn = min(abs(int(s[i : i + 3]) - 753), minn) -print(minn) +n = len(s) +ans = 10**10 +for i in range(n - 2): +    m = int(s[i : i + 3]) +    ans = min(ans, abs(m - 753)) +print(ans)