#include <bits/stdc++.h>
using namespace std;
const int NR = 25;
void Min(int& x, int y) { x = min(x, y); }
void Max(int& x, int y) { x = max(x, y); }
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int n, ans = 0x3f3f3f3f;
char a[NR];
int la[NR];
int p, q;
int len(int x) {
  int res = 0;
  for (int i = x; i <= n; i++) {
    if (a[i] != '0') break;
    res++;
  }
  return res;
}
int main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  for (int i = n; i >= 1; i--)
    if (a[i] == '0' && (!p || !q)) ((!p) ? (p = i) : (q = i));
  if (p && q) Min(ans, (n - p) + (n - q) - 1);
  for (int i = 1; i <= n; i++) la[a[i] - '0'] = i;
  if (la[2] && la[5]) {
    if (la[2] == 1 && la[5] == 2 && len(3) < n - 2)
      Min(ans, n - 2 + n - 2 + len(3));
    else if (la[5] == 1 && la[2] == 2 && len(3) < n - 2)
      Min(ans, n - 2 + n - 2 + 1 + len(3));
    else if (la[2] == 1 && len(2) < n - 1 && la[5] > len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[5] - 1);
    else if (la[2] == 1 && len(2) < n - 2 && la[5] == len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[5] - 1);
    else if (la[5] == 1 && len(2) < n - 1 && la[2] > len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[2]);
    else if (la[5] == 1 && len(2) < n - 2 && la[2] == len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[2]);
    else
      Min(ans, n - la[2] + n - la[5] + (la[2] > la[5]) - 1);
  }
  if (la[7] && la[5]) {
    if (la[7] == 1 && la[5] == 2 && len(3) < n - 2)
      Min(ans, n - 2 + n - 2 + len(3));
    else if (la[5] == 1 && la[7] == 2 && len(3) < n - 2)
      Min(ans, n - 2 + n - 2 + 1 + len(3));
    else if (la[7] == 1 && len(2) < n - 1 && la[5] > len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[5] - 1);
    else if (la[7] == 1 && len(2) < n - 2 && la[5] == len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[5] - 1);
    else if (la[5] == 1 && len(2) < n - 1 && la[7] > len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[7]);
    else if (la[5] == 1 && len(2) < n - 2 && la[7] == len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[7]);
    else
      Min(ans, n - la[7] + n - la[5] + (la[7] > la[5]) - 1);
  }
  if (la[0] && la[5]) {
    if (la[5] == 1) {
      if (la[0] == len(2) + 1)
        Min(ans, n - la[0] + n - 1 + len(2) - 2);
      else
        Min(ans, n - la[0] + n - 1 + len(2) - 1);
    } else
      Min(ans, n - la[0] + n - la[5] + (la[5] > la[0]) - 1);
  }
  printf("%d\n", (ans == 0x3f3f3f3f) ? -1 : ans);
  return 0;
}
