#include <bits/stdc++.h>
using namespace std;
int main() {
  long long s;
  cin >> s;
  long long ans = 0x7FFFFFFF;
  while (s >= 100) {
    long long num = s % 1000;
    ans = min(ans, abs(num - 753));
    s /= 10;
  }
  cout << ans << endl;
  return 0;
}
