#include <iostream>
using namespace std;

int main()
{
    long long s;
    cin >> s;
    long long result = 1e15;
    while (s >= 100)
    {
        result = min(result, abs(s % 1000 - 753));
        s /= 10;
    }
    cout << result << endl;
}
