#include <bits/stdc++.h>
using namespace std;
string num;
int ans = INT_MAX, len;
int solve(char l, char r) {
  string s = num;
  int mov = 0;
  int t1 = s.rfind(r);
  int t2 = l == r ? s.rfind(l, t1 - 1) : s.rfind(l);
  if (t1 == -1 || t2 == -1) return INT_MAX;
  for (int i = t1; i < len - 1; ++i) swap(s[i], s[i + 1]), ++mov;
  t2 = s.rfind(l, len - 2);
  for (int i = t2; i < len - 2; ++i) swap(s[i], s[i + 1]), ++mov;
  int zero = 0;
  for (int i = 0; i < len; ++i)
    if (s[i] != '0')
      break;
    else if (s[i] == '0')
      ++zero;
  return (len - 2) >= zero * 2 ? mov + zero : INT_MAX;
}
int main() {
  cin >> num;
  len = num.length();
  ans = min(ans, solve('0', '0'));
  ans = min(ans, solve('2', '5'));
  ans = min(ans, solve('5', '0'));
  ans = min(ans, solve('7', '5'));
  return !printf("%d", ans == INT_MAX ? -1 : ans);
}
