#include <iostream>
#include <cmath>
using namespace std;
long long s, n, mn = 1e9;
int main() {
	cin>>s;
	for(; s; s/=10) {
		n = s % 1000;
		mn = min(mn, (long long)abs(n - 753));
	}
	cout<<mn;
	return 0;
}