#include <bits/stdc++.h>
using namespace std;
typedef unsigned int UI;
typedef long int LI;
typedef unsigned long int ULI;
typedef long long int LL;
typedef unsigned long long int ULL;
const LL MOD = 1e9 + 7;
inline int scanInt() {
  int n = 0;
  char ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 1) + (n << 3) + (int)(ch - '0');
    ch = getchar();
  }
  return n * sign;
}
inline LL scanLong() {
  LL n = 0;
  char ch = getchar();
  LL sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 1) + (n << 3) + (LL)(ch - '0');
    ch = getchar();
  }
  return n * sign;
}
int main() {
  string s;
  cin >> s;
  LL n = s.length();
  LL ans = LONG_MAX;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    for (__typeof(n) j = (0) - ((0) > (n)); j != (n) - ((0) > (n));
         j += 1 - 2 * ((0) > (n))) {
      LL num = (s[i] - '0') * 10 + (s[j] - '0');
      LL zeros = 0;
      for (__typeof(n) k = (0) - ((0) > (n)); k != (n) - ((0) > (n));
           k += 1 - 2 * ((0) > (n))) {
        if (k == i || k == j) continue;
        if (s[k] == '0')
          zeros++;
        else
          break;
      }
      if (i != j && num % 25 == 0 && (zeros == 0 || zeros != n - 2)) {
        LL moves;
        if (i < j)
          moves = (n - 1 - j) + (n - 2 - i) + zeros;
        else
          moves = (n - 1 - i) + (n - 1 - j) + zeros;
        ans = min(moves, ans);
      }
    }
  }
  if (ans == LONG_MAX) ans = -1;
  printf("%lld ", ans);
  printf("\n");
}
