#include <bits/stdc++.h>
using namespace std;
string s;
long long stringtoint() {
  long long res = 0;
  for (int i = 0; i < s.size(); i++) res *= 10, res += s[i] - '0';
  return res;
}
bool can_zero() {
  bool zero = false, dzero = false;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == '0') {
      if (!zero)
        zero = true;
      else
        dzero = true;
    }
  return dzero;
}
bool can_25() {
  bool two = false, five = false;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '2')
      two = true;
    else if (s[i] == '5')
      five = true;
  }
  return (two && five);
}
bool can_50() {
  bool zero = false, five = false;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0')
      zero = true;
    else if (s[i] == '5')
      five = true;
  }
  return (zero && five);
}
bool can_75() {
  bool seven = false, five = false;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '7')
      seven = true;
    else if (s[i] == '5')
      five = true;
  }
  return (seven && five);
}
bool can_div() { return can_25() || can_50() || can_75() || can_zero(); }
int solve_on(char c, char c2) {
  int no = 0;
  string s2 = s;
  int cnt = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s2[i] == c) {
      int x = i;
      if (x == 0) {
        int z = 1;
        while (s2[z] == '0') z++;
        no += z - 1;
      }
      while (x < s.size() - 1) swap(s2[x], s2[x + 1]), cnt++, x++;
      break;
    }
  }
  for (int i = s.size() - 2; i >= 0; i--) {
    if (s2[i] == c2) {
      int x = i;
      if (x == 0) {
        int z = 1;
        while (s2[z] == '0') z++;
        no += z - 1;
      }
      while (x < s.size() - 2) swap(s2[x], s2[x + 1]), cnt++, x++;
      break;
    }
  }
  return cnt + (s.size() > 2 ? no : 0);
}
int main() {
  cin >> s;
  if (!can_div()) return cout << -1, 0;
  int mx = 1e9;
  if (can_25()) mx = min(mx, solve_on('5', '2'));
  if (can_50()) mx = min(mx, solve_on('0', '5'));
  if (can_75()) mx = min(mx, solve_on('5', '7'));
  if (can_zero()) mx = min(mx, solve_on('0', '0'));
  cout << mx;
  return 0;
}
