#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 10000 + 10;
string s;
int node[3][2] = {2, 5, 5, 0, 7, 5};
vector<int> vec[2];
int change(int p1, int p2) {
  if (s.size() == 2) return 0;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i == p1 || i == p2) continue;
    if (s[i] == '0')
      cnt++;
    else
      return cnt;
  }
  return INF;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> s;
  int len = s.size();
  int minn = INF;
  int lc1 = -1, lc2 = -1;
  for (int i = len - 1; i >= 0 && lc2 == -1; i--) {
    if (s[i] == '0') lc1 == -1 ? (lc1 = i) : (lc2 = i);
  }
  if (lc1 != -1 && lc2 != -1) minn = (len - 1 + len - 2) - (lc1 + lc2);
  for (int i = 0; i < 3; i++) {
    vec[0].clear();
    vec[1].clear();
    for (int j = 0; j < 2; j++) {
      for (int k = len - 1; k >= 0; k--) {
        if (s[k] - '0' == node[i][j]) {
          vec[j].push_back(k);
        }
      }
    }
    for (int j = 0; j < vec[0].size(); j++) {
      for (int k = 0; k < vec[1].size(); k++) {
        int tmp = abs(len - 1 - vec[1][k]);
        tmp += len - 2 - vec[0][j] + (vec[0][j] > vec[1][k] ? 1 : 0) +
               change(vec[0][j], vec[1][k]);
        minn = min(minn, tmp);
      }
    }
  }
  printf("%d\n", minn >= INF ? -1 : minn);
}
