#include <bits/stdc++.h>
using namespace std;
static const int INF = 10000000;
int ans = INF;
string str;
bool f(char c) { return c != '0'; }
void solve(char target_a, char target_b) {
  string s = str;
  int cnt = 0;
  int pos1 = s.rfind(target_a), pos2 = s.rfind(target_b);
  if (target_a == target_b) {
    pos1 = s.rfind(target_a, pos2 - 1);
  }
  if (pos1 == string::npos || pos2 == string::npos) {
    return;
  }
  if (pos1 > pos2) {
    cnt++;
    swap(pos1, pos2);
  }
  for (int i = pos2; i < s.size() - 1; ++i) {
    cnt++, swap(s[i], s[i + 1]);
  }
  for (int i = pos1; i < s.size() - 2; ++i) {
    cnt++, swap(s[i], s[i + 1]);
  }
  cnt += find_if(s.begin(), s.end(), f) - s.begin();
  ans = min(cnt, ans);
}
int main(int argc, char const *argv[]) {
  cin >> str;
  solve('0', '0');
  solve('2', '5');
  solve('5', '0');
  solve('7', '5');
  if (ans == INF) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
