#include <bits/stdc++.h>
using namespace std;
char s[20];
int pos5, pos2, pos0, pos0_2, pos7, len, ans = 0x7fffffff;
int zeros, z1, z2;
int Gans(int x, int y, int z) {
  int lenx = len - 1 - x, leny = len - 1 - y;
  if (y == len - 1) leny = 0;
  if (x < y) lenx = len - 2 - x;
  if (x == 0 || y == 0) return lenx + leny + z;
  return lenx + leny;
}
int main() {
  pos5 = pos2 = pos0 = pos0_2 = pos7 = -1;
  scanf("%s", s);
  len = strlen(s);
  for (register int i = 1; i < len && s[i] == '0'; ++i) ++zeros;
  for (register int i = 0; i < len; ++i) {
    if (s[i] == '5') pos5 = i;
    if (s[i] == '7') pos7 = i;
    if (s[i] == '2') pos2 = i;
    if (s[i] == '0')
      if (pos0)
        pos0 = pos0_2, pos0_2 = i;
      else
        pos0 = i;
  }
  swap(pos0, pos0_2), z1 = zeros, z2 = zeros;
  if (~pos0_2 && pos0_2 <= zeros) --z1;
  if (~pos0 && pos0 <= zeros) --z2, --z1;
  if (~pos7 && ~pos5) ans = min(ans, Gans(pos7, pos5, zeros));
  if (~pos2 && ~pos5) ans = min(ans, Gans(pos2, pos5, zeros));
  if (~pos5 && ~pos0) ans = min(ans, Gans(pos5, pos0, z1));
  if (~pos0_2 && ~pos0) ans = min(ans, Gans(pos0_2, pos0, z2));
  printf("%d\n", ans == 0x7fffffff ? -1 : ans);
  return 0;
}
