#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int F[3][2] = {{2, 5}, {5, 0}, {7, 5}};
string s;
int len;
vector<int> t[3];
int Abs(int x) { return x < 0 ? -x : x; }
int GetWrongNum(int pos1, int pos2) {
  if (len == 2) return 0;
  int ret = 0;
  for (int i = 0; i < len; i++) {
    if (i == pos1 || i == pos2) continue;
    if (s[i] == '0')
      ret++;
    else
      return ret;
  }
  return INF;
}
int Solve() {
  int ret = INF;
  int pos1 = -1, pos2 = -1;
  for (int i = len - 1; i >= 0 && pos2 == -1; i--) {
    if (s[i] == '0') pos1 == -1 ? (pos1 = i) : (pos2 = i);
  }
  if (pos1 != -1 && pos2 != -1) ret = len - pos1 - 1 + len - pos2 - 2;
  for (int i = 0; i < 3; i++) {
    t[0].clear(), t[1].clear();
    for (int j = 0; j < 2; j++)
      for (int k = len - 1; k >= 0; k--)
        if (s[k] - '0' == F[i][j]) t[j].push_back(k);
    for (int j = 0; j < t[0].size(); j++)
      for (int k = 0; k < t[1].size(); k++) {
        int tmp = len - 1 - t[1][k];
        tmp += len - 2 - t[0][j] + (t[0][j] > t[1][k] ? 1 : 0);
        tmp += GetWrongNum(t[0][j], t[1][k]);
        ret = min(ret, tmp);
      }
  }
  return ret >= INF ? -1 : ret;
}
int main() {
  cin >> s;
  len = s.size();
  int ans = Solve();
  printf("%d\n", ans);
  return 0;
}
