import std.stdio;
import std.algorithm;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto S = to!string(tokens[0]);

	ulong best = 999;
	foreach (i; 0..S.length-2)
	{
		auto num = abs(to!long(S[i..i+3]) - 753);
		if (num < best)
			best = num;
	}

	writeln(best);
	stdout.flush();
/*}catch (Throwable e)
	{
		writeln(e.toString());
	}
readln();*/
}