#include <iostream>
using namespace std;

int main() {
	long S;
	cin >> S;
	int a;
	int out=1000;
	while(S>=100)
	{
	    a=S%1000;
	    if(out>abs(a - 753)) out=abs(a - 753);
	    S=S/10;
	}
	cout << out << endl;
	return 0;
}
