#include <bits/stdc++.h>
using namespace std;
inline void setmin(int &x, int y) {
  if (y < x) x = y;
}
inline void setmax(int &x, int y) {
  if (y > x) x = y;
}
inline void setmin(long long &x, long long y) {
  if (y < x) x = y;
}
inline void setmax(long long &x, long long y) {
  if (y > x) x = y;
}
const int N = 200000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
int solve(string s, char c1, char c2) {
  int n = (int)s.size();
  int p1 = -1, p2 = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == c1) p1 = i;
    if (s[i] == c2) p2 = i;
  }
  if (p1 == -1 || p2 == -1) return inf;
  if ((int)s.size() == 2) return (p1 < p2 ? 0 : 1);
  int f = -1;
  for (int i = 0; i < n; i++)
    if (i != p1 && i != p2 && s[i] != '0') {
      f = i;
      break;
    }
  if (f == -1) return inf;
  int res = f;
  if (p1 < f) p1++;
  if (p2 < f) p2++;
  if (p1 > p2) {
    res++;
    swap(p1, p2);
  }
  res += (n - 1) - p2 + (n - 2) - p1;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  string s;
  cin >> s;
  int n = (int)s.size();
  if ((int)s.size() == 1) {
    cout << -1 << "\n";
    return 0;
  }
  int ans = inf;
  vector<int> zero;
  for (int i = 0; i < n; i++)
    if (s[i] == '0') zero.push_back(i);
  if ((int)zero.size() >= 2)
    setmin(ans, (n - 1) - zero[(int)zero.size() - 1] + (n - 2) -
                    zero[(int)zero.size() - 2]);
  vector<int> g = {25, 50, 75};
  for (int x : g) setmin(ans, solve(s, '0' + x / 10, '0' + x % 10));
  cout << (ans != inf ? ans : -1) << "\n";
  return 0;
}
