#include <bits/stdc++.h>
using namespace std;
int main() {
  std::string in;
  cin >> in;
  int ind_z1 = -1, ind_z2 = -1, ind_t = -1, ind_f = -1, ind_s = -1;
  int n = in.size() - 1;
  bool first = true;
  int ind = 0;
  for (auto it = in.rbegin(); it != in.rend(); ++it) {
    char c = *it;
    if (c == '0') {
      if (first) {
        ind_z1 = ind;
        first = false;
      } else if (ind_z2 == -1) {
        ind_z2 = ind;
      }
    } else if (c == '2' && ind_t == -1) {
      ind_t = ind;
    } else if (c == '5' && ind_f == -1) {
      ind_f = ind;
    } else if (c == '7' && ind_s == -1) {
      ind_s = ind;
    }
    ind++;
  }
  int d_00 = -1, d_25 = -1, d_50 = -1, d_75 = -1;
  if (ind_z1 != -1 && ind_z2 != -1) {
    d_00 = ind_z1 + (ind_z2 - 1);
  }
  if (ind_z1 != -1 && ind_f != -1) {
    d_50 = ind_z1 + (ind_f - 1);
    if (ind_z1 > ind_f) d_50++;
  }
  if (ind_f != -1 && ind_t != -1) {
    d_25 = ind_f + (ind_t - 1);
    if (ind_f > ind_t) d_25++;
    if (in[1] == '0' && (ind_f == n || ind_t == n)) {
      int i;
      for (i = 1; i <= n; i++) {
        if (in[i] != '0' && i != n - ind_t && i != n - ind_f) break;
      }
      d_25 += i - 1;
      if (n - ind_t == i - 1 || n - ind_f == i - 1) d_25--;
    }
  }
  if (ind_f != -1 && ind_s != -1) {
    d_75 = ind_f + (ind_s - 1);
    if (ind_f > ind_s) d_75++;
    if (in[1] == '0' && (ind_f == n || ind_s == n)) {
      int i;
      for (i = 1; i <= n; i++) {
        if (in[i] != '0' && i != n - ind_s && i != n - ind_f) break;
      }
      d_75 += i - 1;
      if (n - ind_s == i - 1 || n - ind_f == i - 1) d_75--;
    }
  }
  auto min = -1;
  for (auto d : {d_00, d_25, d_50, d_75}) {
    if (d != -1) {
      if (min == -1) {
        min = d;
      } else {
        min = std::min(min, d);
      }
    }
  }
  cout << min << '\n';
  return 0;
}
