import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string s) {
    int ans = int.max;
    for (int i = 0; i + 3 <= s.length; i++) {
        int x = s[i..i + 3].to!int;
        ans = min(ans, abs(753 - x));
    }
    return ans;
}

void main() {
    string s = read!string;
    writeln(calc(s));
}
