#include <iostream>
#include <cstdlib>
using namespace std;

int main() {
	long int s,d;
	cin >> s;
	int min = 1000;
	
	for(int i=0;i<8;i++){
		d = abs(s%1000-753);
		if(d<min) min = d;
		s = s/10;
	}

	cout << min << endl;

	return 0;
}