#include <bits/stdc++.h>
using namespace std;
int myabs(int a) { return a > 0 ? a : -a; }
int a[25];
char s[25];
int check00(int n) {
  int i, j;
  for (i = n; i >= 1; i--) {
    if (a[i] == 0) break;
  }
  if (i == 0) return -1;
  for (j = n; j >= 1; j--) {
    if (a[j] == 0 && i != j) break;
  }
  if (j == 0) return -1;
  return 2 * n - i - j - 1;
}
int check50(int n) {
  int i, j, k;
  for (i = n; i >= 1; i--) {
    if (a[i] == 0) break;
  }
  if (i == 0) return -1;
  for (j = n; j >= 1; j--) {
    if (a[j] == 5) break;
  }
  if (j == 0) return -1;
  if (j == 1) {
    for (k = 2; k <= n; k++) {
      if (a[k] != 0) break;
    }
    if (i < k) return (n - 1 - j) + (n - i) + (k - j - 1) - 1;
    return (n - 1 - j) + (n - i) + (k - j - 1);
  }
  if (j == n) return n - i;
  return myabs(n - 1 - j) + n - i;
}
int check5(int n, int p) {
  int i, j, k;
  int cnt = 0;
  for (i = n; i >= 1; i--) {
    if (a[i] == 5) break;
  }
  if (i == 0) return -1;
  for (j = n; j >= 1; j--) {
    if (a[j] == p) break;
  }
  if (j == 0) return -1;
  if (i < j) {
    if (i == 1) {
      for (k = 2; k <= n; k++) {
        if (a[k] == 0)
          cnt++;
        else if (k == j)
          continue;
        else
          break;
      }
      if (k == n + 1 && n != 2) return -1;
    }
    if (j == n) cnt -= 2;
    return cnt + myabs(n - 1 - j) + n - i + 1;
  } else {
    if (n == 2) return 0;
    if (j == 1) {
      for (k = 2; k <= n; k++) {
        if (a[k] == 0)
          cnt++;
        else if (k == i)
          continue;
        else
          break;
      }
      if (k == n + 1 && n != 2) return -1;
    }
    return cnt + myabs(n - j - 1) + n - i;
  }
}
int main() {
  int n, i;
  scanf("%s", s);
  n = strlen(s);
  for (i = 1; i <= n; i++) {
    a[i] = s[i - 1] - '0';
  }
  int minn = 0x3f3f3f3f;
  if (check00(n) >= 0) minn = min(minn, check00(n));
  if (check5(n, 2) >= 0) minn = min(minn, check5(n, 2));
  if (check5(n, 7) >= 0) minn = min(minn, check5(n, 7));
  if (check50(n) >= 0) minn = min(minn, check50(n));
  printf("%d\n", minn == 0x3f3f3f3f ? -1 : minn);
}
