#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  int min = 999;
  int tmp;
  while (N >= 100) {
    tmp = abs(753 - N % 1000);
    if (min > tmp) {
      min = tmp;
    }
    N = N / 10;
  }
  cout << min;
  return 0;
}
