S = eval(input())



li = []

for i in range(0, len(S)-2):

    sli = int(S[i:i+3])

    li.append(sli)



ans = 1000

for j in li:

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



print(ans)

S = eval(input())



ans = min(abs(int(S[i:i+3]) - 753) for i in range(len(S) - 2))

print(ans)
S = eval(input())
li = []
for i in range(0, len(S) - 2):
    sli = int(S[i : i + 3])
    li.append(sli)
ans = 1000
for j in li:
    ans = min(ans, abs(j - 753))
print(ans)

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

-li = [] -for i in range(0, len(S) - 2): -    sli = int(S[i : i + 3]) -    li.append(sli) -ans = 1000 -for j in li: -    ans = min(ans, abs(j - 753)) +ans = min(abs(int(S[i : i + 3]) - 753) for i in range(len(S) - 2))