#include <bits/stdc++.h>
using namespace std;
bool ok(char x) {
  if (x == '0' or x == '2' or x == '5' or x == '7') return true;
  return false;
}
int main() {
  string n;
  cin >> n;
  if (n.size() < 2) return puts("-1"), 0;
  map<int, pair<int, int>> v;
  pair<int, int> x;
  x = make_pair(-1, -1);
  v[0] = v[2] = v[5] = v[7] = x;
  for (int i = 0; i < n.size(); i++) {
    if (!ok(n[i])) continue;
    pair<int, int> aux = v[n[i] - '0'];
    vector<int> teste;
    teste.push_back(aux.first);
    teste.push_back(aux.second);
    teste.push_back(i);
    sort(teste.begin(), teste.end());
    v[n[i] - '0'] = make_pair(teste[1], teste[2]);
  }
  vector<int> ans(4, 0);
  int len = n.size();
  if (len == 3 and n[1] == '0') {
    if (n[2] == '0')
      return puts("0"), 0;
    else {
      if (n[0] == '5')
        return puts("2"), 0;
      else if (n[2] == '5')
        return puts("1"), 0;
      else
        return puts("-1"), 0;
    }
  }
  if (v[0].first == -1)
    ans[0] = 100000000;
  else {
    ans[0] = -(v[0].second - len + 1) + -(v[0].first - len + 2);
  }
  if (v[2].second == -1 or v[5].second == -1)
    ans[1] = 100000000;
  else {
    if (n[1] == '0' and (v[2].second == 0 or v[5].second == 0)) {
      bool ajuda = false;
      int kkk;
      for (kkk = 2; kkk < len; kkk++) {
        if (n[kkk] == '0') continue;
        ajuda = true;
        break;
      }
      ans[1] = kkk - 1;
      if (v[2].second == kkk) {
        if (kkk = len - 1)
          ans[1] = 100000000;
        else {
          v[2].second = 1;
        }
      } else if (v[5].second == kkk) {
        if (kkk = len - 1)
          ans[1] = 100000000;
        else {
          v[5].second = 1;
        }
      }
    }
    ans[1] += -(v[2].second - len + 2) + -(v[5].second - len + 1) +
              (v[5].second < v[2].second ? 1 : 0);
  }
  if (v[5].second == -1 or v[0].second == -1)
    ans[2] = 100000000;
  else {
    if (n == "50") return puts("0"), 0;
    if (n[1] == '0' and v[5].second == 0) {
      bool ajuda = false;
      int kkk;
      for (kkk = 2; kkk < len; kkk++) {
        if (n[kkk] == '0') continue;
        ajuda = true;
        break;
      }
      if (!ajuda)
        ans[2] = 100000000;
      else {
        if (v[0].second < kkk) v[0].second = kkk;
        ans[2] = kkk - 1;
      }
    }
    ans[2] += -(v[5].second - len + 2) + -(v[0].second - len + 1) +
              (v[0].second < v[5].second ? 1 : 0);
  }
  if (v[7].second == -1 or v[5].second == -1)
    ans[3] = 100000000;
  else {
    if (n[1] == '0' and (v[7].second == 0 or v[5].second == 0)) {
      bool ajuda = false;
      int kkk;
      for (kkk = 2; kkk < len; kkk++) {
        if (n[kkk] == '0') continue;
        ajuda = true;
        break;
      }
      ans[3] = kkk - 1;
      if (v[7].second == kkk) {
        if (kkk = len - 1)
          ans[3] = 100000000;
        else {
          v[7].second = 1;
        }
      } else if (v[5].second == kkk) {
        if (kkk = len - 1)
          ans[3] = 100000000;
        else {
          v[5].second = 1;
        }
      }
    }
    ans[3] += -(v[7].second - len + 2) + -(v[5].second - len + 1) +
              (v[5].second < v[7].second ? 1 : 0);
  }
  int resp = 100000000;
  for (int i = 0; i < 4; i++) resp = min(resp, ans[i]);
  if (resp >= 100000000)
    puts("-1");
  else
    cout << resp << endl;
  return 0;
}
