#include <bits/stdc++.h>
using namespace std;
int min_moves;
void d(int a, int b, int n, int min_nz = 2) {
  if (a && b) {
    fprintf(stderr, " a: %d, b: %d, n: %d, min_nz: %d = ", a, b, n, min_nz);
    if (a > b) --a;
    min_moves = min(min_moves, (n - 1 - a) + (n - b) + min_nz - 2);
    fprintf(stderr, "%d\n", min_moves);
  }
}
int main(int argc, char *argv[]) {
  int n = 0;
  int two = 0;
  int five = 0;
  int seven = 0;
  int fst_zero = 0;
  int snd_zero = 0;
  char c;
  bool zero_was_second = false;
  int min_nz = 300;
  while (cin >> c) {
    if (c < '0' || c > '9') break;
    c -= '0';
    n++;
    switch (c) {
      case 0:
        if (fst_zero) {
          if (snd_zero) {
            fst_zero = snd_zero;
            snd_zero = n;
          } else {
            snd_zero = n;
          }
        } else {
          fst_zero = n;
          if (n == 2) {
            two = 0;
            seven = 0;
            zero_was_second = true;
          }
        }
        break;
      case 2:
        two = n;
        break;
      case 5:
        five = n;
        break;
      case 7:
        seven = n;
        break;
    }
    if (zero_was_second && c) {
      min_nz = min(min_nz, n);
    }
  }
  min_moves = 30 * n + 5;
  d(fst_zero, snd_zero, n);
  if (!zero_was_second || five > 2) {
    d(two, five, n);
    d(seven, five, n);
  }
  if (zero_was_second) {
    if (min_nz != two) {
      d(two, five, n, min_nz);
    }
    if (min_nz != seven) {
      d(seven, five, n, min_nz);
    }
  }
  d(five, fst_zero, n);
  d(five, snd_zero, n);
  if (min_moves > 30 * n) {
    cout << -1 << endl;
  } else {
    cout << min_moves << endl;
  }
  return 0;
}
