#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
string n;
int len;
int solve_00() {
  int pos[20], cnt = 0;
  for (int i = 0; i < len; i++)
    if (n[i] == '0') pos[++cnt] = i;
  if (cnt < 2) return inf;
  return len - 1 - pos[cnt] + len - 2 - pos[cnt - 1];
}
int solve_other(int l1, int l2) {
  int pos1 = -1, pos2 = -1, ret = 0;
  string tn = n;
  for (int i = 0; i < len; i++) {
    if (tn[i] - '0' == l1) pos1 = i;
    if (tn[i] - '0' == l2) pos2 = i;
  }
  if (pos1 == -1 || pos2 == -1) return inf;
  int lpos = min(pos1, pos2), rpos = max(pos1, pos2);
  for (int i = rpos; i < len - 1; i++, ret++) swap(tn[i], tn[i + 1]);
  if (lpos == 0)
    for (int i = 1; tn[i] == '0' && i < len - 1; i++, ret++)
      if (i == len - 2) return inf;
  ret += len - 2 - lpos + (lpos == pos2);
  return ret;
}
int main() {
  cin >> n;
  len = n.size();
  int ans = solve_00();
  ans = min(ans, solve_other(2, 5));
  ans = min(ans, solve_other(5, 0));
  ans = min(ans, solve_other(7, 5));
  if (ans == inf) ans = -1;
  cout << ans;
  return 0;
}
