#include <bits/stdc++.h>
using namespace std;
long long ans = 100;
string s;
string reqdd[4] = {"00", "25", "50", "75"};
long long get(long long m) {
  long long reqd = 0, check = 0;
  string str = s;
  long long len = str.size();
  for (long long j = 1; j >= 0; j--) {
    long long k = len - 1;
    if (j == 0) k--;
    long long storek = k;
    for (; k >= 0; k--) {
      if (str[k] == reqdd[m][j]) {
        for (long long idx = k; idx < storek; idx++) {
          swap(str[idx], str[idx + 1]);
          reqd++;
        }
        break;
      }
    }
    if (k == -1) return 100;
  }
  if (str[0] == '0') {
    long long j;
    for (j = 1; j <= len - 3; j++) {
      if (str[j] != '0') {
        reqd += j;
        break;
      }
    }
    if (j == len - 2) return 100;
  }
  return reqd;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> s;
  for (long long i = 0; i < 4; i++) {
    ans = min(ans, get(i));
  }
  if (ans == 100) ans = -1;
  cout << ans;
  return 0;
}
