#include <bits/stdc++.h>
using namespace std;
template <typename T>
void dbg(T a) {}
template <typename T, typename... Arg>
void dbg(T a, Arg... arg) {}
const int maxn = (1e6) + 7;
const int inf = (1e9) + 7;
const long long LLinf = (1e18) + 7;
const long double eps = 1e-9;
const long long mod = 1e9 + 7;
int ile(vector<int> V) {
  int res = 0;
  while (((int)(V).size()) && V.back() == 0) {
    V.pop_back();
    res++;
  }
  if (((int)(V).size()) == 0) return 10000;
  return res;
}
int rob(vector<int> V, int a, int b) {
  int cnt = 0;
  for (int i = 0; i < ((int)(V).size()); i++)
    if (V[i] == a) {
      for (int j = i - 1; j >= 0; j--) {
        swap(V[j], V[j + 1]);
        cnt++;
      }
      break;
    }
  for (int i = 1; i < ((int)(V).size()); i++)
    if (V[i] == b) {
      for (int j = i - 1; j > 0; j--) {
        swap(V[j], V[j + 1]);
        cnt++;
      }
      break;
    }
  if (V[0] == a && V[1] == b)
    return cnt + ile(V);
  else
    return 1000;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<int> V;
  while (n > 0) {
    V.push_back(n % 10);
    n /= 10LL;
  }
  int res = 1000;
  res = min(res, rob(V, 0, 0));
  res = min(res, rob(V, 5, 2));
  res = min(res, rob(V, 0, 5));
  res = min(res, rob(V, 5, 7));
  if (res < 100)
    cout << res;
  else
    cout << "-1";
  return 0;
}
