#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 0x3f3f3f3f;
long long n;
int a[20], b[20], last;
vector<int> p[10];
void split(long long n) {
  while (n) {
    a[++last] = n % 10;
    b[last] = a[last];
    n /= 10;
  }
}
long long move(int src, int dest) {
  a[dest] = a[src];
  for (int i = src; i > dest; i--) a[i] = a[i - 1];
  return src - dest;
}
int findNoZero() {
  if (last == 2) return last;
  for (int i = last; i > 2; i--)
    if (a[i] > 0) return i;
  return -1;
}
long long trans(int d1, int d2) {
  for (int i = 1; i <= last; i++) a[i] = b[i];
  long long ans = 0;
  if (d1 == 0 && d2 == 0) {
    if (p[0].size() < 2) return inf;
    return p[0][0] - 1 + p[0][1] - 2;
  }
  if (p[d1].empty() || p[d2].empty()) return inf;
  if (p[d2][0] < p[d1][0]) {
    ans += move(p[d2][0], 1);
    ans += move(p[d1][0], 1);
  } else {
    ans += move(p[d1][0], 1);
    ans += move(p[d2][0], 2);
  }
  int noZero = findNoZero();
  if (noZero == -1) return inf;
  return ans + last - noZero;
}
long long solve() {
  if (n <= 100) {
    if (n == 100 || n == 75 || n == 50 || n == 25) return 0;
    if (n == 57 || n == 52)
      return 1;
    else
      return -1;
  }
  split(n);
  for (int i = 1; i <= last; i++) p[a[i]].push_back(i);
  long long ans = inf;
  ans = min(ans, trans(0, 0));
  ans = min(ans, trans(5, 2));
  ans = min(ans, trans(0, 5));
  ans = min(ans, trans(5, 7));
  return ans == inf ? -1 : ans;
}
int main() {
  cin >> n;
  cout << solve() << endl;
  return 0;
}
