#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long int n = s.size();
  long long int ans = 1e18;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (i == j) continue;
      string t = s;
      long long int cnt = 0;
      for (long long int k = i; k < n - 1; k++) {
        swap(t[k], t[k + 1]);
        cnt++;
      }
      for (long long int k = j - (j > i); k < n - 2; k++) {
        swap(t[k], t[k + 1]);
        cnt++;
      }
      long long int start_non_zero = -1;
      for (long long int k = 0; k < n; k++) {
        if (t[k] != '0') {
          start_non_zero = k;
          break;
        }
      }
      for (long long int k = start_non_zero; k > 0; k--) {
        swap(t[k], t[k - 1]);
        cnt++;
      }
      long long int no = atoll(t.c_str());
      if (no % 25 == 0) ans = min(ans, cnt);
    }
  }
  if (ans == 1e18)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
