#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long OO = (long long)1e9;
const int dx[] = {0, 1, -1, 0, 1, -1, 1, -1};
const int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long fast_power(long long base, long long power) {
  if (power == 1) return base;
  if (power % 2 == 0)
    return fast_power((base * base), power / 2);
  else
    return (base * fast_power((base * base), power / 2));
}
void Qalbaz() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(4);
}
int solve(string str, string st) {
  int x = -1, y = -1;
  int ans = 0;
  for (int i = str.size() - 1; i >= 0; i--) {
    if (str[i] == st[1]) {
      x = i;
      break;
    }
  }
  if (x == -1) return OO;
  for (int i = x; i < str.size() - 1; i++) {
    str[i] = str[i + 1];
    ans++;
  }
  str[str.size() - 1] = st[1];
  for (int j = str.size() - 2; j >= 0; j--) {
    if (str[j] == st[0]) {
      y = j;
      break;
    }
  }
  if (y == -1) return OO;
  for (int i = y; i < str.size() - 2; i++) {
    str[i] = str[i + 1];
    ans++;
  }
  if (str[0] == '0') {
    x = -1;
    for (int j = 1; j < str.size() - 2; j++) {
      if (str[j] != '0') {
        x = j;
        break;
      }
    }
    if (x == -1) return OO;
    return (ans + x);
  }
  return ans;
}
int main() {
  Qalbaz();
  string str;
  cin >> str;
  int ans = OO;
  ans = solve(str, "00");
  ans = min(ans, solve(str, "25"));
  ans = min(ans, solve(str, "50"));
  ans = min(ans, solve(str, "75"));
  if (ans == OO)
    cout << -1;
  else
    cout << ans;
  return 0;
}
