s=list(map(str,eval(input())))



lst=[]

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

	total=s[i]+s[i+1]+s[i+2]

	ans=abs(753-int(total))

	lst.append(ans)

	



print((min(lst)))
s=list(map(str,eval(input())))



ans=753-111 #最大値

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

	total=s[i]+s[i+1]+s[i+2]

	new=abs(753-int(total))

	ans=min(ans,new)

	



print(ans)
s = list(map(str, eval(input())))
lst = []
for i in range(len(s) - 2):
    total = s[i] + s[i + 1] + s[i + 2]
    ans = abs(753 - int(total))
    lst.append(ans)
print((min(lst)))

s = list(map(str, eval(input())))
ans = 753 - 111  # 最大値
for i in range(len(s) - 2):
    total = s[i] + s[i + 1] + s[i + 2]
    new = abs(753 - int(total))
    ans = min(ans, new)
print(ans)

-lst = [] +ans = 753 - 111  # 最大値 -    ans = abs(753 - int(total)) -    lst.append(ans) -print((min(lst))) +    new = abs(753 - int(total)) +    ans = min(ans, new) +print(ans)