ans=0

dif=1000

s=eval(input())

n=len(s)

for i in range(n-2):

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

  if abs(753-tmp)<dif:

    ans=tmp

    dif=abs(753-ans)

print(dif)
S=eval(input())

ans=10**5

for i in range(len(S)-3+1):

    t=S[i:i+3]

    ans=min(ans,abs(753-int(t)))

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

S = eval(input())
ans = 10**5
for i in range(len(S) - 3 + 1):
    t = S[i : i + 3]
    ans = min(ans, abs(753 - int(t)))
print(ans)

-ans = 0 -dif = 1000 -s = eval(input()) -n = len(s) -for i in range(n - 2): -    tmp = int(s[i : i + 3]) -    if abs(753 - tmp) < dif: -        ans = tmp -        dif = abs(753 - ans) -print(dif) +S = eval(input()) +ans = 10**5 +for i in range(len(S) - 3 + 1): +    t = S[i : i + 3] +    ans = min(ans, abs(753 - int(t))) +print(ans)