#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,avx2")
using namespace std;
int get00(string& s) {
  int ttl = 0;
  int ct = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '0') {
      ct++;
      ttl += s.size() - i - ct;
      if (ct == 2) {
        return ttl;
      }
    }
  }
  return (1 << 30);
}
int get50(string& s, char fir, char sec) {
  if (s.size() == 1) {
    return (1 << 30);
  }
  if (s.back() == '0' && s[s.size() - 2] == '0') {
    return (1 << 30);
  }
  int ttl = 0;
  bool ok5 = false, ok0 = false;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == sec && !ok0) {
      ok0 = true;
      ttl += s.size() - i - 1;
      if (i == 0) {
        if (s[1] == '0') {
          int k;
          for (k = 1; k < s.size() && s[k] == '0'; k++)
            ;
          k--;
          ttl += k;
        }
      }
    }
    if (s[i] == fir && !ok5) {
      ok5 = true;
      if (i == s.size() - 1) {
        continue;
      }
      if (i == 0) {
        if (s[1] == '0') {
          if (sec == '0' && ttl == s.size() - 2) {
            ttl = (s.size() - 2) * 2;
            continue;
          } else {
            int k;
            for (k = 1; k < s.size() && s[k] == '0'; k++)
              ;
            k--;
            ttl += k;
          }
        }
      }
      if (ok0) {
        ttl += s.size() - i - 2;
      } else {
        ttl += s.size() - i - 1;
      }
    }
  }
  if (ok0 && ok5) {
    return ttl;
  }
  return (1 << 30);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::cout << std::fixed << std::setprecision(20);
  string s;
  cin >> s;
  int ans = min(min(get00(s), get50(s, '5', '0')),
                min(get50(s, '7', '5'), get50(s, '2', '5')));
  if (ans == (1 << 30)) {
    ans = -1;
  }
  cout << ans << '\n';
}
