function Main(input) {
    parseInt(input);
    var num = input.split("");
    
    var diff = [];
    
    for ( var i=0; i<num.length; i++) {
        var temp = num.slice(i, i+3).join("");
        diff.push(Math.abs( 753 - temp ));
    }
    
    var answer = diff.reduce((n, m) => n <= m? n: m);
    console.log(answer);
    
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));