s=eval(input());print((min(abs(int('0'+s[i:i+3])-753)for i in range(9))))
s=eval(input());print((min(abs(eval(s[i:i+3]+'-753'))for i in range(9))))
s = eval(input())
print((min(abs(int("0" + s[i : i + 3]) - 753) for i in range(9))))

s = eval(input())
print((min(abs(eval(s[i : i + 3] + "-753")) for i in range(9))))

-print((min(abs(int("0" + s[i : i + 3]) - 753) for i in range(9)))) +print((min(abs(eval(s[i : i + 3] + "-753")) for i in range(9))))